Introduction to the use of php setcookie() function

怪我咯
Release: 2023-03-13 17:36:02
Original
1379 people have browsed it

setcookie()FunctionSends an HTTP cookie to the client.

Cookie is avariablesent 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 is automatically 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.

php setcookieParameters of the functionDescription

Usage:

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

Parameter Description
name is required. Specifies the name of the cookie.
value required. Specifies the value of the cookie.
expire Optional. Specifies the validity period of the cookie.
path Optional. Specifies the server path for cookies.
domain Optional. Specifies the domain name for the cookie.
secure Optional. Specifies whether cookies are transmitted over asecureHTTPS connection.

Example

Set and send cookie:

  
Copy after login
  
Copy after login

The above is the detailed content of Introduction to the use of php setcookie() function. 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
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!