First, what is a cookie
A cookie is a mechanism for saving user information on a client browser, which is transmitted over the HTTP protocol
Ii. precautions in the use of cookies
1.cookie security is low and cannot be stored as confidential or important information in a cookie
2.cookie is limited in size and can only hold text information
3.cookie in the header of HTTP means that there is no HTML text output before the operation of the cookie in the PHP script
Third, the function method in the use of cookies
1.SetCookie function
Setcookie (name, value, expire, path, domain, secure);
Name---> Key name
Value---> Values
Expire---> Cookie expiration point in time (a standard UNIX time stamp)
Path---> Settings you can use the paths of cookie scripts, for example:/blog
Domain---> Set up a server that uses cookies to connect, for example: www.163.com
Secure---> Set whether to use HTTPS transport cookie by default without using HTTPS on setting to 1
Setcookie (' name ', ' Timor ', Time () +3600); ---> Set expiration point after one hours
Setcookie (' name ', ' Google ', Time () +3600, '/blog ', ' www.google.com ', 1);
Set the cookie to expire after one hours, the browser can only use HTTPS to pass cookies to the script file under www.google.com/blog
Cookie passing Array
Setcookie ("Arr[name]", ' Timor ', Time () +3600);
When receiving: $_cookie[' arr '][name]
2. Receiving cookies
In the script to use the cookie
Use $_cookie[' name '] to get the value of a COOKIE
Receives the value of an array
Setcookie ("Arr[name]", ' Timor ', Time () +3600);
When receiving: $_cookie[' arr '][name]
3. Delete Cookies
Setcookie (' name ', ' Timor ', Time () +3600);
Direct deletion: Setcookie (' name ');
Expire the cookie: Setcookie (' name ', ', Time ()-60);
Application of Cookies in PHP