IE / Edge session cookie problems using cookie_lif

2019-07-27 08:06发布

Since a couple of days (at least, that I'm aware of), I cannot login to my website using Internet Explorer or Edge. The login does work using Firefox and Chrome! I have witnessed the problem on other computers as well, indicating that it is not a local browser problem.

I am aware that IE / Edge silently drop cookies from domains with a _ in the subdomain, however in my situation there is none.

After allot of sweat and pain, I have reduced the script to the bare minimum to replicate the problem.

I have also found the the problem, but I have no true solution.

<?PHP
    ini_set( 'session.cookie_lifetime', '3600' );

    if( session_id() == '' )
        session_start( );

    $i = 1;
    if( isset( $_POST['logout'] ) ) {
        unset( $_SESSION['loggedin' . $i] );
        session_destroy();
        header( 'Location: http://jbtje.com/test' . $i . '.php' );
    }
    if( isset( $_POST['login'] ) ) {
        $_SESSION['loggedin' . $i] = 'LOGGED IN: ' . $i;
        header( 'Location: http://jbtje.com/test' . $i . '.php' );
    }
?><!DOCTYPE html>
<html>
<head>
<title>TEST <?PHP $i ?></title>
</head>
<body>
<?PHP echo 'You are currently ' . (isset($_SESSION['loggedin' . $i]) ? $_SESSION['loggedin' . $i] : 'not logged in ' . $i); ?>
<form method="POST"><input type="submit" name="login" value="login" /></form>
<form method="POST"><input type="submit" name="logout" value="logout" /></form>

</body>
</html>

Test site: http://jbtje.com/test1.php

If you press the login button, the text should change to "You are currently LOGGED IN". But, it does not.

IF however you comment the ini_set line out, (and change $i to 2): http://jbtje.com/test2.php it does work....

Why does setting cookie_lifetime using PHP cause IE and Edge to not store the cookie? (and how to solve this...?)

Best regards, Jeffrey

0条回答
登录 后发表回答