PHP注销失败,未设置($ _SESSION ['user'])不起作用

时间:2019-02-25 18:00:25

标签: php html session

这个问题已经有一个多星期了,我开始相信它与代码无关。

这是我的会话页面:

<?php
session_start();
include('dbConfigBDO.php');
include('SafeRedirect.php');

if(!isset($_SESSION['login_user'])){
    safe_redirect('login.php');
    die();
}
?>

我在登录后设置了$_SESSION['login_user'],并在每个页面中调用session.php。我也有一个注销页面:

<?php
session_start();
require 'SafeRedirect.php';
unset($_SESSION['login_user']);
session_destroy();
safe_redirect('login.php');
?>

即使在注销后,这里的问题仍然可以通过使用会话来访问我试图阻止的页面。

可能有什么问题吗?

编辑:我的SafeRedirect.php页,我从here中使用过它

<?php
function safe_redirect($url, $exit=true) {
    if (!headers_sent()){

        header('HTTP/1.1 301 Moved Permanently');
        header('Location: ' . $url);

        header("Connection: close");
    }

    print '<html>';
    print '<head><title>Redirecting you...</title>';
    print '<meta http-equiv="Refresh" content="0;url='.$url.'" />';
    print '</head>';
    print '<body onload="location.replace(\''.$url.'\')">';

    print 'You should be redirected to this URL:<br />';
    print "<a href=$url>'$url'</a><br /><br />";

    print 'If you are not, please click on the link above.<br />';

    print '</body>';
    print '</html>';

    if ($exit) exit;
}
?>

2 个答案:

答案 0 :(得分:0)

确保

之后需要session.php
if(!isset($_SESSION['login_user'])){
          safe_redirect('login.php');
          die();
       }

答案 1 :(得分:0)

这个问题不是必须的。这可能是由于浏览器缓存了一些数据而引起的。您在html中尝试过这些功能吗?

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />