注意:会话已经开始,我无法结束我的会话

时间:2016-06-16 13:34:45

标签: php session internet-explorer-11

首先我认为这只是一个IE问题。但是现在我启用了错误代码,这显示了这个:

注意:会话已经启动 - 忽略第7行/var/www/html/login.php中的session_start()

第7行是会话启动命令。

我有三个文件。 index.php,auth.php login.php ,其中包含所有登录过程:

的index.php

<?php

echo "<a href=\"/login.php\">Log in</a>";

?>

auth.php

$_user_ = 'admin';
$_password_ = 'password';

session_start();

$url_action = (empty($_REQUEST['action'])) ? 'logIn' : $_REQUEST['action'];
$auth_realm = (isset($auth_realm)) ? $auth_realm : '';

if (isset($url_action)) {
if (is_callable($url_action)) {
    call_user_func($url_action);
} else {
    echo 'Function does not exist, request terminated';
};
};

function logIn() {
global $auth_realm;

if (!isset($_SESSION['username'])) {
    if (!isset($_SESSION['login'])) {
        $_SESSION['login'] = TRUE;
        header('WWW-Authenticate: Basic realm="'.$auth_realm.'"');
        header('HTTP/1.0 401 Unauthorized');
        echo '<h1>Not authorized!</h1>';
        echo '<p>You must enter a valid login and password.</p>';
        echo '<a href="?action=logOut">Log in</a> | ';
        echo '<a href="../">Back to the Website</a></p>';
        exit;
    } else {
        $user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
        $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
        $result = authenticate($user, $password);
        if ($result == 0) {
            $_SESSION['username'] = $user;
        } else {
            session_unset($_SESSION['login']);
            errMes($result);
            exit;
        };
    };
};
}

function authenticate($user, $password) {
global $_user_;
global $_password_;

if (($user == $_user_)&&($password == $_password_)) { return 0; }
else { return 1; };
}

function errMes($errno) {
switch ($errno) {
    case 0:
        break;
    case 1:
        echo '<h1>Not authorized!</h1>';
        echo 'Username and password are incorrect.';
        echo '<p><a href="?action=logOut">Log in</a> | ';
        echo '<a href="../">Back to the Website</a></p>';
        break;
    default:
        echo 'Unknown error';
};
}

function logOut() {

session_destroy();
session_unset(); 

if (isset($_SESSION['username'])) {
    session_destroy($_SESSION['username']);
    foreach(array_keys($_SESSION) as $k) unset($_SESSION[$k]);
    echo "<h1>You've successfully logged out</h1>";
    echo '<a href="?action=logIn">Log In</a> | ';
    echo '<a href="../">Back to the Website</a>';
} else {
    header("Location: ?action=logIn", TRUE, 301);
};
if (isset($_SESSION['login'])) { session_unset($_SESSION['login']); };
exit;
}

的login.php

<?php

$auth_realm = 'My Website';

require_once 'auth.php';

session_start();
if(!isset($_SESSION['username'])) {
die('Please login first <a href="login.php?action=logIn">log in</a>.');
}
echo "<p>You've logged in as {$_SESSION['username']} ";
echo '<a href="?action=logOut">Log out</a></p>'

?>
  1. 从index.php开始,然后点击登录并输入&#34; admin&#34;和#34;密码&#34;
  2. 点击退出
  3. 点击&#34;返回网站&#34;
  4. 现在点击&#34;登录&#34;再次
  5. 按取消
  6. 点击&#34;返回网站&#34;
  7. 点击登录。
  8. ==&GT;现在您已登录,但未传递用户名和密码。这是一个安全缺陷,只适用于IE 11.我尝试使用几个不同的选项来删除会话,但没有任何帮助。谁能帮帮我?

    我还使用Chrome对此进行了测试,此处它正常运行,我被迫在第7点之后传递登录数据。

1 个答案:

答案 0 :(得分:0)

尝试以这种方式退出:

unset($_SESSION['username']);
session_destroy();
setcookie('PHPSESSID','',time()-3600,'/','',0,0); //unless you changed the PHP session cookie name