Home  >  Article  >  Backend Development  >  How to set php cookie to never expire

How to set php cookie to never expire

藏色散人
藏色散人Original
2020-08-18 10:40:044379browse

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

How to set php cookie to never expire

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!

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