I wanted to do a feature this morning. After the user logs in, I save the user's name to the cookie but I started using the method of reading the cookie, but no effect, later found that using Setcookie () must take time to be able, let me introduce.
Grammar
Setcookie (Name,value,expire,path,domain,secure)
Parameter description
Name is required. Specifies the name of the cookie.
Value is required. Specifies the value of the cookie.
Expire is optional. Specify the validity period of the cookie.
Path is optional. Specifies the server path of the cookie.
Domain is optional. Specifies the domain name of the cookie.
Secure is optional. Specifies whether to transfer cookies through a secure HTTPS connection.
example, a simple assignment to a cookie
| The code is as follows |
Copy Code |
$value = "My cookie value"; Send a cookie that expires in the 24 child Setcookie ("TestCookie", $value, Time () +3600*24); ?> |
Example, a two-dimensional array is stored in a cookie
a.php
| The code is as follows |
Copy Code |
$cart _info[0][0] = "1123"; $cart _info[1][0] = "5334521"; $cart _info[1][2] = "DF"; $cart _info[4][2] = "Fefe"; Setcookie ("Xia", Serialize ($cart _info)); ?> |
b.php
| The code is as follows |
Copy Code |
$other = stripslashes ($_cookie[' Xia '); Print_r (Unserialize ($other)); ?> |
http://www.bkjia.com/PHPjc/628686.html www.bkjia.com true http://www.bkjia.com/PHPjc/628686.html techarticle I wanted to do a feature this morning. After the user logs in I saved the user's name to a cookie but I started using the method of reading the cookie, but it didn't work, and later found using Setcookie () behind ...