www.webdeveloper.com
Results 1 to 3 of 3

Thread: Cookie Expiration Problem

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    92

    Cookie Expiration Problem

    I am having a problem with Google Chrome and Internet Explorer not properly handling the setcookie time() function. Firefox and Safari work fine.

    This is the code that is causing problems in Chrome/IE.

    PHP Code:
    setcookie("cookiename",$cookievalue ,time()+60,"/"); 
    They are both approx. 7 hours behind and they only way I can get the cookie to set is if I set the expiration time to at least the following.

    PHP Code:
    setcookie("cookiename",$cookievalue ,time()+20000,"/"); 
    I have checked the server time and it's set correctly. I have checked the time on my computer and it is accurate as well.

    How come this is not working in those browsers?

    What is the cross-browser solution to get a cookie to expire 1 minute from the current time?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,535
    Maybe a work-around would be to set the cookie for a comparatively long time, but also set a session value which is the actual desired expiration timestamp, maybe using the cookie name as the $_SESSION array key. Then on each page request, if the cookie is set, see if the corresponding $_SESSION value is either not set or has expired, and if so, unset that specific $_COOKIE value.

    Yeah, it's a kludge, but might keep you going pending someone coming up with a "real" solution.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2005
    Posts
    92
    Well, I'd rather try and figure out what the actual problem is that is causing only these particular browsers to mishandle the expiration times.

    Clearly there is some issue with the way they handle the time function and I'm assuming there must be a logical solution that doesn't involve a workaround.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles