Home >Backend Development >PHP Problem >How to set php cookie to never expire
In PHP, you can set a longer validity period to ensure that cookies never expire. Setting statements such as "setcookie("cookie_name", "cookie_value", time() 99 * 365 * 24 * 3600); ".
Recommended: "PHP Video Tutorial"
When setting a cookie in PHP, if the validity period is not specified, then The life cycle is a period of time for the browser, which can also be called non-save. It will disappear after the browser is closed and opened again.
There is no parameter to specify whether to expire or not. The general method is to set a longer validity period, 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 php cookie to never expire. For more information, please follow other related articles on the PHP Chinese website!