Kristian_C Posted December 27, 2006 Share Posted December 27, 2006 Hey, if i use this :if (empty($_SESSION['username'])){echo "<script LANGUAGE='JavaScript'>window.location='index.php';</script>";and add a submit form. will that logout all users that are online on page? ->Kristian_C Link to comment Share on other sites More sharing options...
MrAdam Posted December 27, 2006 Share Posted December 27, 2006 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 More sharing options...
Kristian_C Posted December 27, 2006 Author Share Posted December 27, 2006 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 More sharing options...
MrAdam Posted December 28, 2006 Share Posted December 28, 2006 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 More sharing options...
Kristian_C Posted December 29, 2006 Author Share Posted December 29, 2006 Thanks mate, will try it when im done with the rest ->Kristian_C Link to comment Share on other sites More sharing options...
justsomeguy Posted January 2, 2007 Share Posted January 2, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now