Timed php session
Moderator: General Moderators
Timed php session
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?
Re: Timed php session
I found this on another website, will this work.?
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();
}
Last edited by Benjamin on Wed May 06, 2009 5:48 pm, edited 1 time in total.
Reason: Added [code=php] tags.
Reason: Added [code=php] tags.
Re: Timed php session
I just need it to check if there is any inactivity. I stuff here about forms?
-
ldougherty
- Forum Contributor
- Posts: 103
- Joined: Sun May 03, 2009 11:39 am
Re: Timed php session
Why rely on coding for timing the session? There are settings in your php.ini to manage the session.
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0
; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
If you adjust these values or have your host adjust these values for you you can effectively manage how long sessions are active.
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0
; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
If you adjust these values or have your host adjust these values for you you can effectively manage how long sessions are active.
Re: Timed php session
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.