Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-27-2006, 12:34 PM   PM User | #1
lansing
Regular Coder

 
Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
lansing has a little shameless behaviour in the past
Cookie expire when user is idle

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!
lansing is offline   Reply With Quote
Old 04-27-2006, 01:43 PM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
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...
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Old 04-27-2006, 02:29 PM   PM User | #3
lansing
Regular Coder

 
Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
lansing has a little shameless behaviour in the past
Quote:
Originally Posted by raf
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?
lansing is offline   Reply With Quote
Old 04-27-2006, 03:11 PM   PM User | #4
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
info on session-cookies --> http://uk.php.net/setcookie

example setting a sessioncookie, from that same resource
PHP Code:
$value 'something from somewhere';
setcookie("TestCookie"$value); 
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Old 04-27-2006, 06:50 PM   PM User | #5
Calilo
Regular Coder

 
Join Date: Jun 2002
Location: Mex
Posts: 122
Thanks: 0
Thanked 0 Times in 0 Posts
Calilo is an unknown quantity at this point
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
Calilo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:11 AM.


Advertisement
Log in to turn off these ads.