Reputation: 1938
I am setting several cookies in PHP. One of them, when set, is always deleted. Here is how I set them:
setcookie("UserName",$_COOKIE['UserName'],time() + (60*60*24*7));
setcookie("KeepPost",'',time() + (60*60*24*7));
The first one gets set and expires in a week, the second one gets set, but is already deleted and expires in 1970.
I'm doing it the same way for both of them, even in the same place, what is going on?
Upvotes: 1
Views: 66
Reputation: 24579
You cannot set a cookie with an empty value. Check out the docs under the Common Pitfalls section:
If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.
If this is a flag, give it a value of 1
so it has a value and will not be automatically deleted.
setcookie("KeepPost", 1, time() + (60*60*24*7));
Upvotes: 2