How to set php cookie to never expire

藏色散人
Release: 2023-03-04 17:30:01
Original
4310 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!