Remove a cookie


Question

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?

1
237
3/26/2009 3:05:49 PM

Accepted Answer

You May Try this

if (isset($_COOKIE['remember_user'])) {
    unset($_COOKIE['Hello']); 
    setcookie('Hello', null, -1, '/'); 
    return true;
} else {
    return false;
}
254
7/10/2019 6:53:10 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon