Home > Article > Backend Development > How to set cookies not to expire in php?
In PHP, you can use the setcookie() function to set a longer validity period for the cookie so that the cookie does not expire; the syntax is "setcookie(cookie_name,cookie_value, time() 99*365*24*3600);" .
## Recommended: "PHP Video Tutorial"
Validity period of cookie:
Default: The session period ends (that is, the browser is closed). By default, the cookie will be expired when the browser is closed. Invalid, this cookie is a temporary cookie or session. Cookie supports setting the validity period. The third parameter of setcookie can set the validity period of the cookie. The validity period is represented by a timestamp. (The following one is set for 60 seconds, but after one minute, the cookie will expire regardless of whether the browser is closed)php sets the cookie to not expire
Use setcookie() to set a longer validity period for the cookie so that the cookie does not expire, such as 99 years (time is in seconds and needs to be multiplied by 365 days, 24 hours, and 3600 seconds):setcookie("cookie_name", "cookie_value", time() + 99 * 365 * 24 * 3600);
The above is the detailed content of How to set cookies not to expire in php?. For more information, please follow other related articles on the PHP Chinese website!