【发布时间】:2013-11-10 02:21:02
【问题描述】:
早安,
我在拼凑一个简单的登录系统时遇到了一些问题。它在 Firefox 和 Chrome 中完美运行,但对于我来说,我似乎无法在 Windows 8 上的 IE10 中结束会话。
这是我用于注销的代码。我在这里尝试了一些变体,似乎没有任何效果。
<?
session_start();
include("database.php");
include("login.php");
//deletes cookies by setting the time in the past, negative to what was done while creating the cookie
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
setcookie("cookname", "", time()-60*60*24*100, "/");
setcookie("cookpass", "", time()-60*60*24*100, "/");
}
?>
<html>
<title>Logging Out</title>
<body>
<?
if(!$logged_in){
echo "You are not currently logged in, logout failed. Please click <a href='http://www.website.ca/admin'>here</a> to login.";
}
else{
//Kill session variables (could use some work)
unset($_SESSION['username']);
unset($_SESSION['password']);
$_SESSION = array(); // reset session array
unset($_SESSION); //new code to unset session array
session_destroy(); // destroy session.
echo "You have successfully <b>logged out</b>. You will be automatically redirected.";
echo '<script type="text/JavaScript">setTimeout("location.href = \'http://www.website.ca/admin\';",2000);</script>';
}
?>
</body>
</html>
这是我用来验证页面的代码,我将它作为我想要密码保护的所有页面的第一行:
<?
//includes
session_start();
include("database.php");
include("login.php");
//chcek if logged in
if (!$logged_in){
die("You must be logged in to view this page. Click <a href='http://www.website.ca/admin'>here</a> to login.");
} else {
}
?>
有什么想法吗?
我收到以下错误:
警告:未知:打开(/var/php_sessions/sess_7a91f7a2f211673ba26734a04f96586b,O_RDWR)失败:第 0 行的未知中没有此类文件或目录 (2) 警告:未知:无法写入会话数据(文件)。请在第 0 行的 Unknown 中验证 session.save_path 的当前设置是否正确(/var/php_sessions)
【问题讨论】:
-
除了
session_destroy之外,您为什么还要为其他事情烦恼?为什么要手动使用 cookie? -
我尝试只使用 session_destroy,它也不起作用。我不确定您所说的手动使用 cookie 是什么意思,您能解释一下吗?
-
“不起作用”没有任何意义,因为您没有解释它如何不起作用。手动使用 cookie = 使用
$_COOKIE和setcookie。 -
我很抱歉。当我仅使用 session_destroy 尝试代码时,它仍然无法在 Windows 8 上的 IE 10 中终止会话。在 Windows 7 上的 IE 10 中运行良好。我已经退出游戏一段时间了,还没有接触过代码在几年内。你建议我用什么来代替 $_COOKIE 和 setcookie?我会做一些阅读。
-
搜索“标头已发送”(SO 上的点击量约为 10 亿次)并确保您在开发时启用了
display_errors。 TL;DR:在开始或销毁会话之前,您不得产生任何输出。