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
When you enter 0
for time, you mean "now" (+0s from now is actually now) for the browser and it deletes the cookie.
setcookie("key", NULL, 0, "/");
I checked it in chrome browser that gives me:
Name: key
Content: Deleted
Created: Sunday, November 18, 2018 at 2:33:14 PM
Expires: Sunday, November 18, 2018 at 2:33:14 PM
If you want to delete the cookie completely from all your current domain then the following code will definitely help you.
unset($_COOKIE['hello']);
setcookie("hello", "", time() - 300,"/");
This code will delete the cookie variable completely from all your domain i.e; " / " - it denotes that cookie variable's value all set for all domain not just for current domain or path. time() - 300 denotes that it sets to a previous time so it will expire.
Thats how it's perfectly deleted.
A clean way to delete a cookie is to clear both of $_COOKIE
value and browser cookie file :
if (isset($_COOKIE['key'])) {
unset($_COOKIE['key']);
setcookie('key', '', time() - 3600, '/'); // empty value and old timestamp
}
It's simple!
setcookie("cookiename", "cookievalue", 1);
You have to delete cookies with php in your server and also with js for your browser.. (They has made with php, but cookie files are in the browser client too):
An example:
if ($_GET['action'] == 'exit'){
// delete cookies with js and then in server with php:
echo '
<script type="text/javascript">
var delete_cookie = function(name) {
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
};
delete_cookie("madw");
delete_cookie("usdw");
</script>
';
unset($_COOKIE['cookie_name']);
unset($_COOKIE['cookie_time']);
Set the value to "" and the expiry date to yesterday (or any date in the past)
setcookie("hello", "", time()-3600);
Then the cookie will expire the next time the page loads.