Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete cookie from browser?

Is there any way of instructing a web browser to completely delete one's cookie set with PHP?

I do not want to expiry it or wait for the browser to be closed.

With delete I mean to actually not have it listed inside the cookie's list anymore.

like image 221
mr-euro Avatar asked Aug 12 '09 16:08

mr-euro


People also ask

How do I delete a cookie in Windows 10?

Delete cookies from a specific siteUnder Cookies and data stored, select Manage and delete cookies and site data > See all cookies and site data and search for the site whose cookies you want to delete. Select the down arrow to the right of the site whose cookies you want to delete and select Delete .

Is deleting cookies a good idea?

You definitely should not accept cookies – and delete them if you mistakenly do. Outdated cookies. If a website page has been updated, the cached data in cookies might conflict with the new site. This could give you trouble the next time you try to upload that page.


1 Answers

Try something like this to delete all cookies:

foreach ($_COOKIE as $name => $value) {
    setcookie($name, '', 1);
}

The value 1 is the expire value and it represents one second after the begin of the Unix time epoch. So it’s always already expired.

like image 157
Gumbo Avatar answered Sep 26 '22 08:09

Gumbo