Page 1 of 1
keeping cookies
Posted: Sat Dec 13, 2003 5:07 pm
by C
hey all,
i am a php newb and i just figured out how to set, read, and delete cookies...im very happy. anyway, my question is this: if i set a cookie with my current code:
Code: Select all
<?php
setcookie('flavor', 'chocolate chip');
echo ("you got cookies");
?>
than it will set a cookie. but the cookie it sets only lasts for how ever long i have that browser window open for. how do i make it so that the cookie is permenant and so i can read it even if i re-launch my browser?
Thanks!
Posted: Sat Dec 13, 2003 5:17 pm
by volka
http://php.net/set_cookiebool setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])
[...]
Parameter: expire
Description: The time the cookie expires. This is a unix timestamp so is in number of seconds since the epoch. In otherwords, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime().
Examples: time()+60*60*24*30 will set the cookie to expire in 30 days. If not set, the cookie will expire at the end of the session (when the browser closes).
Posted: Sat Dec 13, 2003 6:37 pm
by C
ah, so if i wanted it to be a cookie that will stay for ever id set it so that it is plus 838383827174813193912 days or somthing....THANKS!
Posted: Sun Dec 14, 2003 12:15 am
by Gen-ik
Code: Select all
<?php
// Set a Cookie for 1 day.
setcookie("cookieName", "cookieValue", strtotime("+1 day", time()));
// Set a Cookie for 1 week.
setcookie("cookieName", "cookieValue", strtotime("+1 week", time()));
// Set a Cookie for 1 month.
setcookie("cookieName", "cookieValue", strtotime("+1 month", time()));
// Set a Cookie for 1 year.
setcookie("cookieName", "cookieValue", strtotime("+1 year", time()));
?>
Just a couple of examples.
Hope that helps.