PHP can’t unset cookies

I can’t figure out why I can’t remove a cookie or it’s value:

I have simple log in script, when user enters correct login details, this is

setcookie('logged', $admin['username'], time()+60*60*24*365);

Also, session_start() is present on all pages.

When I want to log off a user, the following happens:

if($page=='logoff') {
    setcookie('logged', "", time() - 3600);
    unset($_COOKIE['logged']); // tried also this
    header("Location: index.php"); // if this is removed, the code below acts like there's no $_COOKIE['logged'] or it's empty (until refresh)

Once it gets redirected to index.php the $_COOKIE[‘logged’] is back with the old value, like something would set it again (nothing does for sure, I even removed the one and only login cookie set line)

I couldn’t find a solution in similar questions. Tested in chrome and IE.

Source: php

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.