Timed php session
Posted: Mon May 04, 2009 10:17 pm
I want to make a session where, it logs the user out if their computer has been inactive for (x) amount of time. How can I do this?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
if(time()-$_SESSION['timeStamp']>= 900) { // 900 sec's
unset($_SESSION['login'])//unset all session variables and redirect to Error page "Session TimedOut"
} else {
//update the session['timeStamp'] with current time
$_SESSION['timeStamp'] = time();
}
You might not always want all your sessions to be deleted after a set amount of time. Not all sessions are used with the same lifetime in mind. It's good to have control over it tooldougherty wrote:Why rely on coding for timing the session? There are settings in your php.ini to manage the session.