Page 1 of 1

Cookies that don't expire?

Posted: Tue Mar 25, 2003 3:53 am
by Tubbietoeter
Hi guys,


I used the search but couldn't find anything that helps me.

Is there a way to set a cookie that doesnt expire? Can I just set the expiration-time to a trillion seconds or something to keep it as long as possible? How long a period can a cookie be set for at max?


Thx,

Steff

Posted: Tue Mar 25, 2003 3:58 am
by mchaggis
If you set it to an extremely long time, and then send a new cookie each time hey visit??

Sorry I can't be more help

Posted: Tue Mar 25, 2003 4:06 am
by Beans
I'll have to agree with mchaggis...

My version is, set it to today's date plus 365 day. Then everytime they visit the site, set the cookie to that. This will add another year to the cookie from the date that they accessed the site.

Of course, that is assuming that they will actually visit your site more than once a year.

Posted: Tue Mar 25, 2003 4:53 am
by twigletmac
Was cleaning out my cookie collection the other day and it looks like the convention for this is to either reset the cookie each time the person visits or to set the cookie to expire in 2079 or something like that.

Mac

Posted: Tue Mar 25, 2003 5:17 am
by Tubbietoeter
How do I specify that it expires in 2079 or do I have to calculate the minutes till that date?

Posted: Tue Mar 25, 2003 9:37 am
by sleepingdanny
Yu can try :arrow:

Code: Select all

<?
setcookie("CookieName") #without using "time()+"
?>
Just so you'll know "time()+3600" = 1 Hour... :P

Code: Select all

<?
setcookie("CookieName",time()+3600);
?>

Posted: Tue Mar 25, 2003 9:48 am
by twigletmac
If you don't set the time argument for setcookie() then the cookie will expire when the browser is closed:
PHP manual - setcookie() wrote:If [time is] not set, the cookie will expire at the end of the session (when the browser closes).
To have a cookie that'll expire in the far distant future use mktime() to do something like:

Code: Select all

$expire_date = mktime(0, 0, 0, 1, 1, 2037);
and then use $expire_date as the argument for expiry time.

Mac

Posted: Wed Mar 26, 2003 10:13 am
by Tubbietoeter
Thanks!! :o)