这是我在logout.php中的代码
<?php
if(isset($_COOKIE['cookie-username']) || isset($_COOKIE['cookie-password'])) {
setcookie("cookie-username", NULL, time()-60*60*24*100);
setcookie("cookie-password", NULL, time()-60*60*24*100);
}
header( 'Location: ../login' ) ;
?>
我可以确认饼干存在,如果我做了一个while循环,我得到了
致命错误: /home/ios/public_html/logout.php 5 b>
这意味着它无法删除cookie ... 我做了很多谷歌搜索,但我无法弄清楚为什么它不会删除所说的饼干......
帮助? 在此先感谢
编辑: 饼干证明: http://cl.ly/1c31120de4b722518b05
创建cookie:
if (isset($_POST['submit'])) {
try {
if (!isset($_POST['username']) || !isset($_POST['password']) || trim($_POST['username']) =='' || trim($_POST['password']) =='') { throw new Exception('All Fields Are Required!');
}
$username = strtolower($_POST['username']);
$password = md5(strtolower($_POST['password']));
include('classes/config.php');
[SQL REMOVED]
foreach ($pdo->query($sql) as $row) {
$dbPassword = $row['password'];
}
if (!isset($dbPassword)) {
throw new Exception('Invalid Username or Password!');
}
if ($dbPassword == $password) {
if (!isset($_COOKIE['cookie-username']) || !isset($_COOKIE['cookie-password'])){
$days = 1;
if (strtolower($_POST['remember']) == 'on') {
$days = 30;
}
setcookie("cookie-username", $username, time()+60*60*24*$days, "/");
setcookie("cookie-password", $password, time()+60*60*24*$days, "/");
}
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=../index">';
}
else if ($dbPassword != $password) {
throw new Exception('Invalid Username or Password!');
}
}
catch (Exception $e) {
$exception = $e->getMessage();
}
}
答案 0 :(得分:1)
删除while循环。 setcookie
不会影响$ _COOKIE。
如果没有帮助,请尝试:
<?php
setcookie("cookie-username", NULL, time()-60*60*24*100, "/", ".yourdomain.com");
setcookie("cookie-password", NULL, time()-60*60*24*100, "/", ".yourdomain.com");
header( 'Location: ../login' ) ;
?>
PS:在cookie中存储登录名/密码也是一个坏主意,出于身份验证的目的,最好在会话中存储一个标志
答案 1 :(得分:0)
<?
setcookie('cookie-username', 0, -1);
setcookie('cookie-password', 0, -1);
header('Location: example.com/path/login');
?>
try
对您无法使用。$_COOKIES
仅在脚本启动时刷新,如果您删除cookie,您将在下次刷新结果时看到。