Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 注销/销毁会话时出现问题_Php_Session_Logout - Fatal编程技术网

Php 注销/销毁会话时出现问题

Php 注销/销毁会话时出现问题,php,session,logout,Php,Session,Logout,在我做的一个小测试中,我很难破坏我的会话 我可以从我的code_login.php文件和header()登录到需要登录的另一个页面。但当我注销时,有时即使我已注销,也可以返回该页面 (会话_start()位于我所有页面的顶部) 这是我的登录代码: $res = $db->query($sql); $num = $res->num_rows; if ($num == 1) { $_SESSION['user'] = array( 'username' =>

在我做的一个小测试中,我很难破坏我的会话

我可以从我的code_login.php文件和header()登录到需要登录的另一个页面。但当我注销时,有时即使我已注销,也可以返回该页面

(会话_start()位于我所有页面的顶部)

这是我的登录代码:

$res = $db->query($sql);
$num = $res->num_rows;

if ($num == 1) {
    $_SESSION['user'] = array(
        'username' => $username;
    );
}
这是注销:

session_start();
$_SESSION = array();
session_destroy();
header('LOCATION: index.php?loggedOut');
这是我的页面顶部,需要登录

session_start();
if (isset($_SESSION['user'])) {
    require some stuff;
} else {
    header('LOCATION: index.php?loginNeeded');
}
但有时我仍然能够在登录后返回到所需的登录页面。

会话_start()

将插入到您设置或取消设置会话的每个页面上,以及用于阅读会话

数据

添加
session_start()在登录代码页顶部:

session_start();
$res = $db->query($sql);
$num = $res->num_rows;

if ($num == 1) {
    $_SESSION['user'] = array(
        'username' => $username;
    );
}

检查您的浏览器是否支持cookies&以及您的php.ini是否支持使用cookies的会话这可能会给您带来一些乐趣