srinivas6203 Posted July 11, 2008 Share Posted July 11, 2008 hi Sorry for my english. I am doing one website. After user logged out. and click browser back button, it is displaying user previous pages. That means session was not destroy correctly. when click backbutton i want to display as "Your session expired. login again". How can i do this. Here is my code. <? session_start(); session_destroy(); header("location:index.php"); ?> $_SESSION['login_user'] is the session variable. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/ Share on other sites More sharing options...
ratcateme Posted July 11, 2008 Share Posted July 11, 2008 found this on php.net <?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. $_SESSION = array(); // If it's desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } // Finally, destroy the session. session_destroy(); ?> Scott. Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/#findComment-587354 Share on other sites More sharing options...
srinivas6203 Posted July 11, 2008 Author Share Posted July 11, 2008 hi thanks for your reply. I tried your script but its not working. It show my previous page when click browser back button. Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/#findComment-587355 Share on other sites More sharing options...
corbin Posted July 11, 2008 Share Posted July 11, 2008 It could be because the page is cached. Often if you hit the back button, even if the page does not cache, it is displayed like it was cached. Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/#findComment-587357 Share on other sites More sharing options...
bluejay002 Posted July 11, 2008 Share Posted July 11, 2008 whether you destroyed the session/remake it or the other way around, you should be checking the session code before proceeding, and maybe then, redirect to the login page. Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/#findComment-587358 Share on other sites More sharing options...
ratcateme Posted July 11, 2008 Share Posted July 11, 2008 this might help telling the browser not to cache your pages. add this to the top of all your pages <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past? ?> Scott. Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/#findComment-587359 Share on other sites More sharing options...
srinivas6203 Posted July 11, 2008 Author Share Posted July 11, 2008 Hi this is also not working. I want to display error message as "your session expired" with login table, when user click back button after he logged out. thanq Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/#findComment-587368 Share on other sites More sharing options...
piyushsharmajec Posted July 11, 2008 Share Posted July 11, 2008 Insted of redirect logout page to index.php by header funtion, we have to write this piece of code after session_destroy. <META HTTP-EQUIV=\"refresh\" content=\"2; URL=index.php\"> "; Link to comment https://forums.phpfreaks.com/topic/114226-session-logout-problem/#findComment-587436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.