PHP settings and read cookies
Concept Understanding:
Cookies are generated by the server and sent to User-agent (typically a browser), and the browser saves the key/value of the cookie to a text file in a directory, The next time you request the same Web site, the cookie is sent to the server (provided the browser is set to enable cookies).
Setcookie (Name,value,expire,path,domain,secure)
PHP Settings Cookie
A. Key and value:
Setcookie ("name", ' Zhangshan ');
B. Set the timeout period:
Setcookie ("name", ' Zhangshan ', Time () +10);
C. Setting the path
Setcookie ("name", ' Zhangshan ', Time () +10, '/');
D. Setting the Access domain
Setcookie ("name", ' Zhangshan ', Time () +10, ' mi.com ');
E. Setting security access values 0 or 1
Note: Cookies can only store strings, and numbers;
PHP Read cookies
A. Direct use of key values $name
B. Hyper global $_cookie[' name '] or $http_cookie_vars[' name ') read
Note A cookie cannot set multiple values as follows:
Setcookie ("name", ' Zhangshan '); Setcookie ("Age", 15);
If you want to set multiple values, you can serialize the array and then save to a variable
$arr = Array (+/-); $arr _str = serialize ($arr); Setcookie ("name", $arr _str);
PHP Delete Cookies
Or