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!
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:
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?
bool 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).
<?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()));
?>