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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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\"> "; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.