Far Cry Posted September 14, 2010 Share Posted September 14, 2010 Hi there, I am wondering if you guys can help me make it so my session times out after a previously set time. I have researched this and found no luck. Here is my code.... <?php session_start(); $username = $_SESSION['username']; $userid = $_SESSION['userid']; ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/213433-manual-php-session-timeout/ Share on other sites More sharing options...
WatsonN Posted September 14, 2010 Share Posted September 14, 2010 So what your wanting to do it make a "timer" that after say 1800 seconds it does something? Link to comment https://forums.phpfreaks.com/topic/213433-manual-php-session-timeout/#findComment-1111177 Share on other sites More sharing options...
petroz Posted September 14, 2010 Share Posted September 14, 2010 Take a look at this.. http://www.php.net/manual/en/function.session-get-cookie-params.php Link to comment https://forums.phpfreaks.com/topic/213433-manual-php-session-timeout/#findComment-1111178 Share on other sites More sharing options...
WatsonN Posted September 14, 2010 Share Posted September 14, 2010 Ok I think I get it, you want to use "lifetime" in your cookies? If so: setcookie(CookieName, $Data, time()+1800); -edit- added code -edit- Link to comment https://forums.phpfreaks.com/topic/213433-manual-php-session-timeout/#findComment-1111179 Share on other sites More sharing options...
WatsonN Posted September 15, 2010 Share Posted September 15, 2010 I think what you want is to just set the cookie experation time: setcookie(CookieName, $data, time()+1800); or do a timer script like this Timer.php <?php session_start(); if($_SESSION['session_count'] == 0) { $_SESSION['session_count'] = 1; $_SESSION['session_start_time']=time(); } else { $_SESSION['session_count'] = $_SESSION['session_count'] + 1; } $session_timeout = 1800; $session_duration = time() - $_SESSION['session_start_time']; if ($session_duration > $session_timeout) { session_unset(); session_destroy(); session_start(); session_regenerate_id(true); setcookie("CookieName", 0, time()-3600); setcookie("Cookie2Name", 0, time()-3600); $_SESSION["expired"] = "yes"; header("Location: ./"); // Redirect to Login Page } else { $_SESSION['session_start_time']=time(); } ?> Link to comment https://forums.phpfreaks.com/topic/213433-manual-php-session-timeout/#findComment-1111196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.