0
votes
<?
if($_POST["Login"])
{
    if (GetRightPassword($_POST["emaillogin"],$_POST["passwordlogin"]))
    {
        $_SESSION["email"] = $_POST["emaillogin"];
        $_SESSION["password"] = $_POST["passwordlogin"];
        echo "Keeping logged in: ".$_POST["keeploggedin"];
        if ($_POST["keeploggedin"])
        {
            setcookie("email", $_POST["emaillogin"], time()+60*60*24*365); 
            setcookie("password", $_POST["passwordlogin"], time()+60*60*24*365);
        }
    }
    else
    {
        echo "Invalid username/password!";
    }
}

if($_POST["Logout"])
{
    $_SESSION["email"] = null;
    $_SESSION["password"] = null;
    setcookie("email", "", time()-900000); 
    setcookie("password", "", time()-900000);
}

echo $_COOKIE["email"];
?>

That's the only code (As far as I can find, I coded it 6 months ago minimum but I'm prety sure there's no more) that writes to cookies or session.

When I click logout, it nulls the session variables, so when the page loads, I'm logged off- Change page again or refresh though, and I'm logged back in again.

Any ideas why? Login isn't being sent when I change page, so I have no idea why.

If it helps, the echo $_COOKIE["email"]; line echos your email even when it's just set it to "".

Edit

I just found more code related to this.

This code is ran before that code.

if(isset($_COOKIE["email"]))
{
$_SESSION["email"] = $_COOKIE["email"];
$_SESSION["password"] = $_COOKIE["password"];
}
1
Are you actually storing passwords in cookies? (Just checking.) Anyways, try using session_destroy(), and also try not setting them to null, but rather unset()ing them. And also, if there's no session_start() anywhere, you need to add that. - Ry-
The session's operating fine. It's just the cookies aren't unsetting. I added some more code I just found while I was browsing my include files. - Ashley Davies

1 Answers

1
votes

set in all your cookies the path and domain. This ensures it's not something like a with and withoud www.

Check the documentation how to do this: http://nl2.php.net/setcookie

This might be the root cause for your problem