View Full Version : Cookie Help
Jasonb61
08-28-2002, 11:35 PM
Can someone explain how to define a cookie life?
Like in my php script I have $COOKIE_LIFE = 3*24*3600; and I know that will set a cookie for 3 Days.... What would I put to set a cookie for 1 Day?
Thanks,
JohnnyX
ShriekForth
08-29-2002, 11:00 PM
$COOKIE_LIFE = 3*24*3600;
you need to set the cookie in seconds.
So in the above example, 3(Days) * 24(hours) * 3600(Seconds in an Hour 60 seconds per min, 60 min per hours)
To set your cookie to 1 day, you would need 24 * 3600 or 86400 seconds. The variable $COOKIE_LIFE is probably being used in the function php setcookie along with time() something link this if it's set server side.
setcookie ("TestCookie", "", time() + $COOKIE_LIFE);
In javascript, you set it with the same number, but getting the server date/time is more reliable than the client date/time.
var exp = new Date(<? echo $COOKIE_LIFE; ?>);
document.cookie = "username=joe; expires=" + exptoGMTString();
ShriekForth
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.