0

I have a problem. So I create a cookie when user is not connected and tried to access an image. And I want to delete this cookie when user login to application. I created like this :

setcookie(self::COOKIE_NAME, $generatedToken, time() + self::COOKIE_LIFETIME_DAY * 86400, self::COOKIE_PATH, $_SERVER['HTTP_HOST']);

And the cookie is correct created, but when I tried to delete the cookie doesn't work.I tried like this :

setcookie(self::COOKIE_NAME, '', 1);

And like this :

unset($_COOKIE[self::COOKIE_NAME]);
setcookie(self::COOKIE_NAME, '', time() - 30);

And the same situation. Can you help me please ?

Harea Costicla
  • 797
  • 3
  • 9
  • 20
  • Are you sure your code is reaching that point? Put an `echo` just above the point to see if it's output on the page. And why have you tagged this question with two version of PHP? Deleting your tags, add back in *one* version. – Styphon Oct 06 '15 at 10:39
  • The code reaching that point.. – Harea Costicla Oct 06 '15 at 11:42
  • This might help you http://stackoverflow.com/questions/686155/remove-a-cookie – Martin Oct 06 '15 at 11:55
  • "Then the cookie will expire the next time the page loads." the next time the page loads, so what you do is unset the cookie and then recall / reload the page. – Martin Oct 06 '15 at 11:56

0 Answers0