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 Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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(); ?> 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.