Home > Backend Development > PHP Problem > What is the method to set cookie time in php

What is the method to set cookie time in php

王林
Release: 2023-03-02 12:26:01
Original
3023 people have browsed it

The method to set cookie time in php is: [setcookie("cookie_name","abcd",time() 3600);]. The setcookie() function sends an HTTP cookie to the client. A cookie is a variable sent to the browser by the server.

What is the method to set cookie time in php

Method to set cookie time:

setcookie("cookie_name", "abcd", time()+3600);
Copy after login

The above code indicates that this cookie has a validity period of 3600 seconds.

Function introduction:

The setcookie() function sends an HTTP cookie to the client.

Cookie is a variable sent by the server to the browser. Cookies are typically small text files that a server embeds on a user's computer. This cookie is sent each time the computer requests a page through the browser.

The name of the cookie is specified as a variable of the same name. For example, if the cookie being sent is named "name", a variable named $user will automatically be created containing the cookie's value.

The cookie must be assigned before any other output is sent.

If successful, the function returns true, otherwise it returns false.

Syntax:

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

Parameter description:

  • name is required. Specifies the name of the cookie.

  • value is required. Specifies the cookie value.

  • expireOptional. Specifies the validity period of the cookie.

  • path is optional. Specifies the server path for cookies.

  • domain is optional. Specifies the domain name for the cookie.

  • secureOptional. Specifies whether cookies are transmitted over a secure HTTPS connection.

The above is the detailed content of What is the method to set cookie 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