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
storing a cookie indefinitely
Moderator: General Moderators
-
davidklonski
- Forum Contributor
- Posts: 128
- Joined: Mon Mar 22, 2004 4:55 pm
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.
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.
- johnperkins21
- Forum Contributor
- Posts: 140
- Joined: Mon Oct 27, 2003 4:57 pm
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.