你好,
我在拼凑一个简单的登录系统时遇到了一些问题。它在 Firefox 和 Chrome 中完美运行,但对于我来说,我似乎无法在 Windows 8 的 IE10 中结束 session 。
这是我用于注销的代码。我在这里尝试了一些变体,似乎没有任何效果。
<?
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) 警告:未知:无法写入 session 数据(文件)。请验证 Unknown on line 0 中 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 销毁(); $_SESSION = 数组();和 $unset($_SESSION);不适用于 IE10?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19869490/