View Full Version : Timed Session Kill
11-07-2007, 11:37 PM
I would like to have My $_SESSION variable destroyed after a certain amount of time. Is there a way that I can have a timeout function or something that after 10 minutes it will destroy this variable?
11-08-2007, 12:14 AM
The way I know of is to store a timestamp in the $_SESSION array and then with each page load check that timestamp and if the time difference is greater than your 10 minutes (or whatever) then destroy the session (and redirect or whatever). It won't "officially" be destroyed until the page is reloaded though; in other words, it won't be right on the 10 minute mark, and if the page never gets reloaded then the session won't be explicitly destroyed (but will expire as all sessions eventually do).
11-08-2007, 01:50 AM
Another thing you might be able to do is set the max lifetime in htaccess to 10 minutes. The only down side of this is it will effect all sessions on your site. This is what I use in one of the htaccess files on a site I'm in charge of
php_value session.gc_maxlifetime 2419200
php_value session.cookie_lifetime 604800
I believe its set for a week or something like that.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.