kadamsurekha Posted June 13, 2007 Share Posted June 13, 2007 hey friends! i have a website wherein users login to browse the other pages of the site. on logout i want the pages to expire. i have php coding so on all the pages i have written session_start() at the beginning and on click of logout hyperlink the logout.php file opens wherein i have written this code: <? session_start(); session_destroy(); echo "U have been successfully logged out"; ?> but still on click of back button of the browser the pages are shown. wht can be the pbm??? Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/ Share on other sites More sharing options...
Yesideez Posted June 13, 2007 Share Posted June 13, 2007 I'd set a session variable. $_SESSION['userid']=$userid; At the beginning of each "logged in" script check if that session variable exists. If not direct back to the login page: <?php if (empty($_SESSION['userid'])) { header("Location: login.php"); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273794 Share on other sites More sharing options...
TreeNode Posted June 13, 2007 Share Posted June 13, 2007 You might want to destroy your sessions variables as well. Here's what I use to uber kill the session and its variables: unset($_SESSION['username']); unset($_SESSION['password']); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } $_SESSION = NULL; session_destroy(); Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273814 Share on other sites More sharing options...
kadamsurekha Posted June 13, 2007 Author Share Posted June 13, 2007 hello! i tried the code u said. but on click of back button of the browser i get this message " The page you are trying to view contains POSTDATA that has expired from cache. If you resend the data, any action the form carried out(such as a search or online purchase will be repeated. To resend the data, click OK. Otherwise, click Cancel. " when i click on OK i get the pages open and work very well. i want the message to be displayed as "Page cannot be displayed" wht should be done???? Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273818 Share on other sites More sharing options...
Yesideez Posted June 13, 2007 Share Posted June 13, 2007 Care to post some code? Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273819 Share on other sites More sharing options...
kadamsurekha Posted June 13, 2007 Author Share Posted June 13, 2007 hey, This is the code i have written for my other pages after login <?php session_start(); include("config.php"); include("opendbs.php"); $username=$_SESSION['user']; //$emailID=$_POST['username']; //$password=$_POST['passwd']; if(empty($_SESSION['user'])) { header("Location: index.php"); exit; } ?> and on the logout.php file i have written this code <? session_start(); unset($_SESSION['user']); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } $_SESSION = NULL; session_destroy(); echo "You have been successfully logged out"; ?> still the pbm persists. help????????????? Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273822 Share on other sites More sharing options...
Yesideez Posted June 13, 2007 Share Posted June 13, 2007 Try this: <?php session_start(); unset($_SESSION['user']); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } $_SESSION = NULL; session_destroy(); header("Location: login.php"); ?> If when you log the user out they're redirected to the login page it should be obvious to them they've been logged out. Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273827 Share on other sites More sharing options...
kadamsurekha Posted June 13, 2007 Author Share Posted June 13, 2007 hey! i tried the statement header("Location: index.php"); after session_destroy(); what i want is like how it displays in yahoo session expired or page cannot be displayed tht way but my pages open afer clicking on back button help???????? Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-273843 Share on other sites More sharing options...
TreeNode Posted June 15, 2007 Share Posted June 15, 2007 There's too many unknowns about your issue. For example, you could be viewing the the cached version of the page you were just looking for, to check this click logout, hit the back button, hit refresh. You can add meta information to not cache your site. Quote Link to comment https://forums.phpfreaks.com/topic/55403-logout-code/#findComment-275511 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.