kadamsurekha Posted June 16, 2007 Share Posted June 16, 2007 hello friends! what code shall i write to logout from the site??? i have a website where i allow the users to access the webpages once they have login. i want the users to logout on click of a logout hyperlink. if user tries to click on the back button of the browser after logging out it should display session expired. i have written the code as session_start(); in all the pages after login and on click of logout hyperlink the logout.php page opens where the code written is <?php session_start(); unset($_SESSION['user']); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } $_SESSION = NULL; $_SESSION['user']=NULL; session_destroy(); header("Location: index.php"); ?> can any1 help me in this???????? thank you Link to comment https://forums.phpfreaks.com/topic/55845-logout-code/ Share on other sites More sharing options...
Full-Demon Posted June 16, 2007 Share Posted June 16, 2007 Just unset() is enough. Perhaps you browser catched the page on the back button. Refresh it a few times to be sure. FD Link to comment https://forums.phpfreaks.com/topic/55845-logout-code/#findComment-275904 Share on other sites More sharing options...
MrSheen Posted June 16, 2007 Share Posted June 16, 2007 The logout.php should be just <? session_destroy(); header... ?> Link to comment https://forums.phpfreaks.com/topic/55845-logout-code/#findComment-275907 Share on other sites More sharing options...
The Little Guy Posted June 16, 2007 Share Posted June 16, 2007 <?php session_start(); $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Logout Success</title> </head> <body> <h1>You have successfully logged out of the system</h1> </body> </html> Link to comment https://forums.phpfreaks.com/topic/55845-logout-code/#findComment-275976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.