Home >Backend Development >PHP Tutorial >How to use setcookie() to assign value to cookie in php_PHP Tutorial
This morning I wanted to make a function. After the user logged in, I saved the user's name in a cookie, but I started to use the method of reading the cookie, but it didn't work. Later I found that using setcookie() must be followed by time. Below I Let me introduce it.
Grammar
setcookie(name,value,expire,path,domain,secure)
Parameter Description
name required. Specifies the name of the cookie.
value required. Specifies the value of the cookie.
expire is optional. 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.
secure Optional. Specifies whether cookies are transmitted over a secure HTTPS connection.
For example, a simple assignment to a cookie
The code is as follows
|
Copy code
|
||||||||
$value = "my cookie value";
setcookie("TestCookie",$value, time()+3600*24); ?>
For example, two-dimensional array is stored in cookie 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 Previous article:The difference between PHP array merge and addition and array_merge_PHP tutorialNext article:The difference between PHP array merge and addition and array_merge_PHP tutorial Related articlesSee more |