Home >Backend Development >PHP Problem >How to set cookies not to expire in php?

How to set cookies not to expire in php?

青灯夜游
青灯夜游Original
2020-09-27 15:43:323464browse

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);" .

How to set cookies not to expire in php?

## 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)

How to set cookies not to expire in php?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn