Page 1 of 1
storing a cookie indefinitely
Posted: Wed Apr 07, 2004 11:55 am
by davidklonski
hello there
I was wondering whether it is possible to set a cookie indefinitely?
I looked at the setcookie() API and the expiration parameter is a Unix timestamp.
Is there a way to send a cookie to the browser which will stay there forever (unless the user deletes it) ?
thanks in advance
Posted: Wed Apr 07, 2004 11:59 am
by JayBird
yeah, just set the cookie to expire in like 40 years or something like that.
Mark
Posted: Wed Apr 07, 2004 12:03 pm
by phait
hi,
Yes it should be possible, although you would have to set an expiration date into the future and then periodically update that expiration date. For example, you might set the cookie to expire a year into the future from when it is set. The whenever a cookied user comes back you simply update the expiration time to the current date + 1 year.
I haven't got the code to hand but that's the way I would do it. There isn't a definitive attribute - that I know of - that makes it live forever without some nursing of the date going on.
Posted: Wed Apr 07, 2004 2:22 pm
by johnperkins21
Why would you make a cookie indefinite? Put it at 5 years or so. How long can you reasonably expect a person to come back to your site using the same PC (without having been formatted and re-loaded)? If you set it to last for 10 years, the cookie would invariably never expire. Or take Bech's idea of setting it to 40 years, but 10 is probably more than enough.
Posted: Wed Apr 07, 2004 4:31 pm
by ol4pr0
I dont think there are much computers around that wont be formatted once every couple of ..... ? ( not years lol )
Posted: Wed Apr 07, 2004 4:37 pm
by mudkicker
i think 1 year is enough. ol4pro says right...

Posted: Wed Apr 07, 2004 4:48 pm
by feyd
Last time I read the cookie spec, it said something like: for ~infinite cookies, just set to one year beyond current time. Anything else wasn't guaranteed to exist...