The phpsetcookie value is null or an empty string is used to delete cookie parsing. Many of my friends will automatically delete the cookie when using setcookie to set the value to NULL or null. let me analyze the reason why the cookie value is NULL or a null string to delete the cookie, when setcookie is set to NULL, the system automatically deletes the cookie, next, let me analyze the reason why the cookie value is null or an empty string is used to delete the cookie. For more information, see.
This is also written in the official document:
#2 setcookie () delete example
The code is as follows: |
|
// Set the expiration date to one hour ago Setcookie ("TestCookie", "", time ()-3600 ); Setcookie ("TestCookie", "", time ()-3600 ,"/~ Rasmus/"," example.com ", 1 ); ?> |
Today, I encountered a strange thing. when I set the cookie, I sent an empty string to $ value. The result was that the cookie was deleted...
The code is as follows: |
|
$ Name = "post_url "; $ Value = ""; Setcookie ($ name, $ value, time () + 60*60*3 ,"/"); |
Go to php 5.4.13 and find out the source code.
The value type in the parameter is char * in C, and value_len indicates its length.
If value_len is 0, the following cookie is written:
The value is "deleted" and the expiration time is Thu. 01-Jan-1970 08:00:01 CST or Thu, 01-Jan-1970 00:00:01 GMT.
It seems that setcookie ($ name, "") can indeed delete this cookie...
Similarly, in php, strval (NULL) = "", so setcookie ($ name, NULL) is equivalent to setcookie ($ name, ""), you can also delete this cookie.
...