Skip to content Skip to sidebar Skip to footer

Any Idea Why I Have To Click The Logout Button Twice To Logout?

This is my code for logout.php When I click LOGOUT on my webpage I'm building, I have to click it twice to logout, any idea why?

Solution 1:

You seem to be using both a session and a cookie, probably for a 'remember me' functionality. However, the logout script only deletes one at a time.

Try to remove the else in the else if.

if (session exists)
{
    destroy session
}

if (cookie exists)
{
    delete cookie
}

Solution 2:

First time you log out, the if is run through, destroying the session. Next time you log out, the else is run through, removing the cookies.

Look at PHP - session_destroy, there's an example on how to handle this.

You can also do this in one run, just do two independent ifs

if (isset($_SESSION['user_id']) {
...
}

if (isset($_COOKIE['user_id']) {
...
}

Post a Comment for "Any Idea Why I Have To Click The Logout Button Twice To Logout?"