我有一个使用AJAX实现的登录,并且在发送响应文本之前,后端的PHP设置了$ _SESSION ['guest']。然后它在前端的JavaScript重定向到访客页面,该页面检查是否isset($ _ SESSION ['guest']),但通常这会导致错误,并且我被带到另一个页面(使用我的else分支)。
我想知道如果可能我太早检查它,那就是为什么isset($ _ SESSION ['guest'])结果为false。但是我在重定向到测试它的页面前倒计时5秒,所以这是我不明白的。
发生了几次(我注销并重新登录)后,它停止失败,我无法让它失败,这显然没有帮助!认为这可能是一个缓存/ cookie问题,但我已经清除了所有这一切,它仍然不会再失败。
任何想法?
//this is the login script snippet
if($rows == 1){
$_SESSION[$type] = $username; //$type is posted over as guest or client. this is valid right?
$_SESSION[$type.'_id'] = $result['id'];
echo $_SESSION['welcome'] = 'You have logged in successfully.';
}
<?php
//snippet from the guest page. session_start() is invoked within the included 'page_top.php'
include('page_top.php');
if(isset($_SESSION['guest'])){
if(isset($_GET['sect'])){
if($_GET['sect'] == 'photography'){
include('view_album.php');
}
else{
include('404.html');
}
}
else{
include('welcome.php');
}
}
else{
include('403.html'); //i get redirected here!
}
include('page_bottom.php');
?>
编辑:我现在想的是,当它失败会话变量只是不获取设置,因为如果我重装我的客人页面,它会导致每次403.html页面,所以它不是一个延迟,它只是没有设置。
它可能是一个缓存问题? – Nanne 2011-05-26 20:00:32
不,我推断,因为我记录它5秒后,它仍然无法正常工作,它必须不是每次都设置变量。我不认为这是一个缓存问题,因为这会更有可能导致在您返回时意外登录,但在我访问开始时总是无法登录我 – 2011-05-28 12:37:03
是否可能是因为我正在设置会话变量的键使用$ type而不是像'client'或'guest'这样的字符串? – 2011-06-01 15:11:21