phpwiz Posted August 9, 2009 Share Posted August 9, 2009 How do i make it so that the user gets logged out if they are inactive for like 10min? Link to comment https://forums.phpfreaks.com/topic/169512-session-end/ Share on other sites More sharing options...
smerny Posted August 9, 2009 Share Posted August 9, 2009 //put this code on all your pages session_start(); //10 minutes $timelimit = 600; //check if he's been inactive for more than the time limit if(time() - $_SESSION['timeout'] > $timelimit) { //destroy session and bring him to the login page if he is out of time session_destroy(); header("Location: login.php"); } //reset his time if he hasn't timed out yet $_SESSION['timeout'] = time(); Link to comment https://forums.phpfreaks.com/topic/169512-session-end/#findComment-894374 Share on other sites More sharing options...
bundyxc Posted August 9, 2009 Share Posted August 9, 2009 //In theory, you'd run this script on every page. //Keep in mind, this is a rough draft. You need to tailor it to your liking. $time = time(); //Declare current time as variable. //Obviously you must create the table first, with whatever fields you'd like. $result = mysql_query('SELECT `lastClick` FROM `table` WHERE `user` = \'' . $user . '\''; //Check the last activity. $lastClick = mysql_result($result, 0); //Make it into a variable. $lastClickPlusTen = $lastClick + 600; //Calculate time ten minutes from then. if ($time > $lastClickPlusTen) { //If it's been over ten minutes, destroy the session. session_destroy() } else { //If it's been less than ten minutes, update this as the new time. mysql_query('UPDATE `table` SET `lastClick` = \'' . $time . '\' WHERE `username` = \'' . $username . '\'' OR die(mysql_error()); } EDIT: ...nevermind that. Using a session is much smarter. Link to comment https://forums.phpfreaks.com/topic/169512-session-end/#findComment-894377 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.