Jump to content

Empty a session?


Kristian_C

Recommended Posts

you should use...

session_destroy()

that will completely destroy the session and effectively log out your users.having...

<script LANGUAGE="JavaScript">window.location=index.php;</script>

...will automatically redirect the user, no matter wether there's a submit button or not. if you're wanting to only redirect your users when they click a button, you need to create a function, and run that function when the user clicks the button. if you are just wanting to automatically redirect a user, i'd use PHP:

Header("Location: index.php");

most likely more reliable than javascript.

Link to comment
Share on other sites

thanks :)but hmm.. whould :

<?if($_POST['out']){session_destroy(username)echo"<script LANGUAGE='JavaScript'>window.location=index.php;</script>";?>

that work? or must i do something else to select the username from somewhere?its a admin fuction so if i want to close down the site and need all users to logout...- Kris

Link to comment
Share on other sites

ohh. session_destroy() has no parameters, using it will only remove YOUR session.to remove everybodies sessions .. you could create a piece of code within your script that reads a variable from either a config file or a database, for example:

<?phpsession_start();// read from file or databaseif ($log_users_out==true) {   session_destroy();}// rest of script?>

that MAY work, i'm not sure. I've never tried anything like it.

Link to comment
Share on other sites

Do a search in the PHP forum for custom session handlers. I posted some code that will let you store sessions in a database instead of the default location. If you use that, you can just delete everything in the database to log everyone out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...