When I want to remove a Cookie I try
unset($_COOKIE['hello']);
I see in my cookie browser from firefox that the cookie still exists. How can I really remove the cookie?
When I want to remove a Cookie I try
unset($_COOKIE['hello']);
I see in my cookie browser from firefox that the cookie still exists. How can I really remove the cookie?
When you enter
0
for time, you mean "now" for the browser.I checked it in chrome browser that gives me:
A clean way to delete a cookie is to clear both of
$_COOKIE
value and browser cookie file :Just set the expiration date to one hour ago, if you want to "remove" the cookie, like this:
or
Source: http://www.php.net/manual/en/function.setcookie.php
You should use the
filter_input()
function for all globals which a visitor can enter/manipulate, like this:You can read more about it here: http://www.php.net/manual/en/function.filter-input.php and here: http://www.w3schools.com/php/func_filter_input.asp
Most of you are forgetting that this will only work on a local machine. On a domain you will need a pattern like this example.
It's simple!
To delete cookie you just need to set the value to NULL:
"If you've set a cookie with nondefault values for an expiration time, path, or domain, you must provide those same values again when you delete the cookie for the cookie to be deleted properly." Quote from "Learning PHP5" book.
So this code should work(works for me):
Setting the cookie:
setcookie('foo', 'bar', time() + 60 * 5);
Deleting the cookie:
setcookie('foo', '', time() + 60 * 5);
But i noticed that everybody is setting the expiry date to past, is that necessary, and why?