Cookie implementation
Cookies are different from sessions. As long as the session is passed to the server, it can be used on this web page. However, if the cookie is not set with attributes, it can only be used under the current path.
Cookie has 5 attributes that are used when using setcookie ("name", value, time, path, domain).
You need to operate the path when you want to use it on other pages. If you use "/" instead of path, it can be used on the entire web page.
When defining time, you need to operate time(), such as
setcookie("name", value, time() + 3600);
This is to save the cookie for 1 hour. The webpage will automatically log out the cookie after one hour;
Use $_COOKIE("name"); to retrieve the cookie value when retrieving cookie data.
Cookie deletion
There are two ways to delete cookies, one is setcookie("name"); the other is to reset the time to 0; setcookie("name", value, 0); that's it
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the implementation of cookies in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.