3

I've got some stubborn cookies that won't delete.

I have

setcookie('rememberme', $cookie, time() + (86400 * 7));

These two codes are on separate pages.

$_COOKIE['rememberme'] = "";
unset($_COOKIE['rememberme']);
setcookie('rememberme', null, -1, '/');

which unsets the cookie for only the page that it is called on. but it remains set on other pages and will remain set even if I come back to the same page with that code removed.

In short, how do you unset; delete; remove; destroy; dismember; trash a cookie FOREVER on all pages in php?

wogsland
  • 9,106
  • 19
  • 57
  • 93
Mathew
  • 117
  • 6
  • To remove the cookie, set the date in the past and use the same key and path you used to create the cookie. Maybe [this](http://stackoverflow.com/questions/10526967/how-to-unset-cookie-in-php?rq=1) will help – styfle Dec 17 '14 at 20:16
  • better to use `time = 1`. -3600 assumes that the user's clock is relatively accurate, which is never a good assumption. – Marc B Dec 17 '14 at 20:17
  • @styfle I have the cookie on the login page to set. And to unset when a user goes to the logout page. Is there any easy work around to this pathing? – Mathew Dec 17 '14 at 20:22
  • 1
    @Mathew The path the cookie applies to is one of the parameters to `setcookie`. As long as that parameter matches the start of the path the user requested, it can be whatever you like, so usually you can just use `'/'`, meaning "this whole domain". – IMSoP Dec 17 '14 at 20:42

0 Answers0