美好的一天,
我一直在拼凑的简单登录系统遇到一些麻烦。它可以在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 {
}
?>
有任何想法吗?
我收到以下错误:
警告:未知:open(/ var / php_sessions / sess_7a91f7a2f211673ba26734a04f96586b,O_RDWR)失败:行0上的未知中没有这样的文件或目录(2)警告:未知:无法写入会话数据(文件)。请在第0行的Unknown中验证session.save_path的当前设置正确(/ var / php_sessions)
最佳答案
通过向setcookie()添加第六个参数解决了该问题,Firefox,Chrome和Opera似乎都自动将第六个字段设置为您的域名。 IE10不会这样做,并且在尝试处理Cookie时似乎会丢失它。在设置cookie以及尝试对其进行修改时,也需要这样做。
损坏的代码:
setcookie("cookname", "", time()-60*60*24*100, "/");
setcookie("cookpass", "", time()-60*60*24*100, "/");
工作代码:
setcookie("cookname", "", time()-60*60*24*100, "/", "YOURDOMAIN.COM");
setcookie("cookpass", "", time()-60*60*24*100, "/", "YOURDOMAIN.COM");
关于php - session_destroy(); $ _SESSION = array();和$ unset($ _ SESSION);不适用于IE10?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19869490/