How to set cookie expiration time in php

王林
Release: 2023-03-04 13:20:02
Original
3312 people have browsed it

How to set cookie expiration time in php: You can use the setcookie() function to set it. The specific usage method is: [setcookie ("mycookie", "123", time() 3600*24);], which means that the cookie will expire after one day.

How to set cookie expiration time in php

#Can be set using the setcookie function.

(Recommended tutorial: php graphic tutorial)

Grammar:

setcookie(name,value,expire,path,domain,secure)
Copy after login

Parameter introduction:

  • name Set the name of the cookie. The value of this parameter must be set.

  • value Set the cookie value. This parameter must be set.

  • expire Optional. Set the validity period of the cookie, usually a timestamp.

  • path Optional. Set the server path for cookies.

  • domain Optional. Domain name to set cookie.

  • secure Optional. Specifies whether to transmit cookies through a secure HTTPS connection

(Video tutorial: php video tutorial)

Example:

Set the cookie to expire after one day

setcookie ("mycookie", "123", time()+3600*24);
Copy after login

time() represents the timestamp of the current time, time() 3600*24 represents the timestamp of the next 24 hours.

Similarly, set the cookie to expire after one year

setcookie ("mycookie", "123", time()+3600*24*365);
Copy after login

The above is the detailed content of How to set cookie expiration time in php. 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