homer.favenir Posted February 3, 2009 Share Posted February 3, 2009 to all, How do I create a session that expires after x minutes of idle? thanks Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/ Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 A session already gets classed as garbage after 24 minutes (usually) so will log any users out. If you want to make the time specific you'll want to create a new table in your db that will store a users last active time and check it everytime they do something to see wether they should be timed out! Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753235 Share on other sites More sharing options...
peranha Posted February 3, 2009 Share Posted February 3, 2009 set "session.gc_maxlifetime" in the php.ini file Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753236 Share on other sites More sharing options...
homer.favenir Posted February 3, 2009 Author Share Posted February 3, 2009 set "session.gc_maxlifetime" in the php.ini file what if i dont have the php.ini? the webhost has it. is there any workaround? thanks Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753239 Share on other sites More sharing options...
peranha Posted February 3, 2009 Share Posted February 3, 2009 ini_set('session.gc_maxlifetime', NEW_VALUE); I believe that will work. Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753243 Share on other sites More sharing options...
homer.favenir Posted February 3, 2009 Author Share Posted February 3, 2009 can i just make a new php.ini and put it in my root folder of my webhost? Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753244 Share on other sites More sharing options...
peranha Posted February 3, 2009 Share Posted February 3, 2009 can i just make a new php.ini and put it in my root folder of my webhost? No, dont think so. Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753246 Share on other sites More sharing options...
homer.favenir Posted February 3, 2009 Author Share Posted February 3, 2009 where in my pages can i put this script? should i just place it in my header.php? thanks Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753248 Share on other sites More sharing options...
homer.favenir Posted February 3, 2009 Author Share Posted February 3, 2009 for the sake of anyone who need this script. <?php session_start(); // set timeout period in seconds $inactive = 60; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { // go to login page when idle session_destroy(); header("Location: logoutpage.php"); } } $_SESSION['timeout'] = time(); ?> Link to comment https://forums.phpfreaks.com/topic/143559-solved-session-time-automatic-logout/#findComment-753264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.