Cookies that don't expire?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Cookies that don't expire?

Post 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
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post 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
Beans
Forum Commoner
Posts: 49
Joined: Mon Dec 23, 2002 3:06 am
Location: Manila, Philippines
Contact:

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

How do I specify that it expires in 2079 or do I have to calculate the minutes till that date?
sleepingdanny
Forum Newbie
Posts: 12
Joined: Thu Mar 20, 2003 4:27 am
Location: Israel

Post 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);
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Last edited by twigletmac on Wed Mar 26, 2003 11:14 am, edited 1 time in total.
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

Thanks!! :o)
Post Reply