Hi all. This seems to me like a trivial question, but I can't seem to find the right answer anywhere.
How do I set the max amount of idle time which can pass before a session will expire?
Thanks in advance, P.
hmmmm, have you looked at the manual? 🙂
int setcookie (string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])
e.g.
setcookie ("TestCookie", $value,time()+3600);
that cookie will expire in 3600 seconds
one option is to manually set the cookie and it's liftime as autumn suggests. But if you are using php's built in session handling you might want to try this.
you can set this in php.ini globally for all your scripts, or with ini_set() if you want to have only this page set a different liftime for a cookie.
look in php.ini for this line
session.cookie_lifetime = 0 ; lifetime in seconds of cookie ; or if 0, until browser is restarted
read more on ini_set here: http://www.php.net/manual/en/function.ini-set.php
I don't know if this is really the best way to do it... but for sessions I have recently tried setting the PHP.ini config variable in my script (only gets set for the lifetime of the script then, since I cannot change the default setting on my ISP's box) for "session.cookielifetime". Do this before you do a session_start() call and all should go well
i.e.
ini_set('session.cookie_lifetime', 1200); session_start();
This will set the cookie lifetime for the session to timeout after 1200 seconds (20 minutes). The cookie will get reset every time this piece of code is run (before/during header output).
Of course, if you have access to your PHP.ini file then you can just change this setting to the required value (the default should be 0 which implies no timeout)