Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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!

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mex
    Posts
    122
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •