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