How to delete cookies in PHP browser: 1. Set the cookie expiration time; 2. Set the cookie value to empty; 3. Use the setcookie method to set the cookie.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
php server deletes browser cookies
1. Set the cookie expiration time
//将过期时间设为一小时前 setcookie("TestCookie", "", time() - 3600); setcookie("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1);
2. Set the cookie value to empty
setcookie($cookiename, '') setcookie($cookiename, NULL);
3. Setcookie in PHP will take effect immediately Problem
Use method setcookie to set cookie, but setcookie will not take effect immediately. If you get $_cookie immediately, you will not get the value. Refresh the page again to get the value.
Look at the cookie item in the network in the chrome developer tools, you will see that there is no value in the request cookie, but there is a value in the response cookie (I don’t know the difference between them yet)
If you want it to take effect immediately, you can setcookie(cookiename,value) and then $_cookie[cookiename]=value
The first step is to create the cookie, and the second step is to assign the value.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of php browser delete cookies. For more information, please follow other related articles on the PHP Chinese website!