Many friends use the Setcookie setting value is empty or null when the system will automatically delete the cookie, let me give you to analyze the cookie value is null or empty string Delete cookie reason, there are need to learn friends can refer to.
This is also the case in the official documentation:
#2 Setcookie () Delete Example
The code is as follows |
Copy Code |
Set the expiration date to one hour ago Setcookie ("TestCookie", "", Time ()-3600); Setcookie ("TestCookie", "", Time ()-3600, "/~rasmus/", "example.com", 1); ?> |
Today encountered a strange thing, in the Setcookie, passed an empty string to $value, the result is this cookie was deleted ...
The code is as follows |
Copy Code |
$name = "Post_url"; $value = ""; Setcookie ($name, $value, Time () +60*60*3, "/"); |
To go through PHP 5.4.13 source of the results learned
The type of value in the parameter in the C language is char *, and a value_len indicates its length.
If Value_len is 0, the following cookie is written:
The value is "deleted", 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 actually delete this cookie ...
Similarly, in PHP, strval (null) = = = "", so Setcookie ($name, NULL) is also equivalent to Setcookie ($name, ""), which can also delete this cookie.
http://www.bkjia.com/PHPjc/632123.html www.bkjia.com true http://www.bkjia.com/PHPjc/632123.html techarticle Many friends use the Setcookie setting value is empty or null when the system will automatically delete the cookie, let me give you to analyze the cookie value is null or empty string Delete cookie reason, it is necessary ...