SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    quick cookie question

    How do i make a cookie for an indefinate period of time, I never want it to expire?
    Cheers

    Coup

  2. #2
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can specify a value that means "never" expire, but you can set the value for a very long time, i.e. 50 years.

    PHP Code:
    setcookie("test""testme"time()+60*60*24*365*50); 

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i though the date system used in a cookie was similar to a unix time stamp, and doesn't that only go up to something 2027, admittedly thats long enough but i was just wondering.
    or is the cookie date differant?
    Cheers

    Coup

  4. #4
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you are correct January 19, 2038 is the date at which timestamps will overflow. I wasn't thinking, so you want something smaller than fifty years

  5. #5
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Generally cookies that are intended to last "forever" are set to 1 year, and then refreshed (i.e. send the cookie again with a new expiration date 1 year hence) on every page load. This avoids the overflow problem (which actually is not inherent to the cookie itself but to systems that store the date in a Unix timestamp format - cookies use the format "Tue, 12-Jun-2008 17:38:45 GMT") while still giving you your "forever cookie".
    PHP questions? RTFM
    MySQL questions? RTFM


Bookmarks

Posting Permissions

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