0

I have a cookie, that I set with the following command:

setcookie( 'auth', 'cookie data' , time() + 3600, '/', '.mydomain.com', true, true );

when I log out, I call a function to clear it, which does this:

setcookie( 'auth', "", time() - 3600, '/', '.mydomain.com', true, true );

However, if I then refresh the page, $_COOKIE['auth'] is still set, and returns the old 'cookie data' value that should be gone!

What am I missing?

Greg Schoppe
  • 576
  • 1
  • 7
  • 22

2 Answers2

0
unset($_COOKIE['auth']);  
setcookie('auth', ''); 
Jack
  • 329
  • 2
  • 5
  • 13
  • although I hate code-dumps too, unsetting the `$_COOKIE['auth']` global before doing the set in the past took care of the issue. – Greg Schoppe Feb 18 '14 at 20:51
0
  1. make sure you haven't already sent headers http://www.php.net/manual/en/function.headers-sent.php

  2. make sure you are sending headers. Are you outputting anything else? If not, echo anything to make sure headers are sent before exit.

  3. remove from cookie global array also

    if(isset($_COOKIE['auth'])) { unset($_COOKIE['auth']); }

  4. if your session name is 'auth', any change to session data may rewrite the session cookie

troseman
  • 1,842
  • 20
  • 19
  • headers have not been sent at that point, but are sent before the script terminates – Greg Schoppe Feb 18 '14 at 20:45
  • try removing from cookie globals also, you haven't by any chance called your session 'auth'? because that might do it also if you change session data after deleting cookie – troseman Feb 18 '14 at 20:49