...

View Full Version : Cookie expire when user is idle



lansing
04-27-2006, 12:34 PM
I have cookies set to expire at a set time when a user logs in. How do I go about making the cookie expire after " X " amount of time when the user comes idle? I am still new to using cookies still...if I have the cookie to expire in 600 seconds, then will it expire 600 seconds from login or from the time he becomes idle?

If this is a common question, then just say what it is or reply with links to other threads. I tried just searching for cookies, but didn't find anything...I wouldn't know the code when I see it anyways.

Thanks!

raf
04-27-2006, 01:43 PM
if you send a cookie with a fixed expirationmoment (like time()+600 ), then the cookie will be removed on the client after that date-time is passed. Even if the user restarts his computer before the set date-time, the cookie will be there.
there is no such notion as 'idle' or so that comes into play here. You just set a fixed date-time until the cookie should remain on the client. If the client has another system date-time as the server (for instance, your server is GMT and the clients machine is GMT+1 hour, then the cookie will immediately expire. the cookie-removal is done through a browsermechanisme (server has nothing to do with this).

if you don't specify an expiration date-time, then the cookie will be stored on the client until the session ends (and the browser is closed). so you could just set session-cookies and then tune your garbage collection parameters so that the sessions expire after about 10 minutes after the client requested his last page...

lansing
04-27-2006, 02:29 PM
if you send a cookie with a fixed expirationmoment (like time()+600 ), then the cookie will be removed on the client after that date-time is passed. Even if the user restarts his computer before the set date-time, the cookie will be there.
there is no such notion as 'idle' or so that comes into play here. You just set a fixed date-time until the cookie should remain on the client. If the client has another system date-time as the server (for instance, your server is GMT and the clients machine is GMT+1 hour, then the cookie will immediately expire. the cookie-removal is done through a browsermechanisme (server has nothing to do with this).

if you don't specify an expiration date-time, then the cookie will be stored on the client until the session ends (and the browser is closed). so you could just set session-cookies and then tune your garbage collection parameters so that the sessions expire after about 10 minutes after the client requested his last page...I have searched google & this forum. I can't find much on session-cookies. I found a thread in the ASP section of this forum, but my host doesn't support ASP. Is the session-cookies a ASP function only? Can you give an example of session-cookies code?

raf
04-27-2006, 03:11 PM
info on session-cookies --> http://uk.php.net/setcookie

example setting a sessioncookie, from that same resource


$value = 'something from somewhere';
setcookie("TestCookie", $value);

Calilo
04-27-2006, 06:50 PM
As raf said, the cookie will expire when you tell it to expire, if you set the cookie to expire in 60 s, then it will expire in 60 seconds from when it was created, so if you want the cookie to expire 60 s of idle time, you can just

re-set the cookie expire time everytime the user loads a new page, so on every page you have to add a setcookie() with the correct time, so if the user opens a page, the cookie will expire in 60 s, but if after 50 seconds the user opens a new page, the cookie will be set again to expire in 60 s,

hope thats clear.

Calilo



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum