Cookie第二次失败后失败

时间:2014-05-29 17:25:17

标签: javascript php cookies

所以我有点问题。

在我的网站上,用户登录主页,他们可以在网站内注销。

现在,用户可以登录,然后重新登录。当他们登录时,会设置cookie,当他们注销时,cookie将被删除。

但是,如果他们登录(设置了cookie),注销(删除了cookie),再次登录(再次设置cookie),并尝试再次注销,则不会删除cookie。

知道为什么会这样吗?

以下是我用来设置Cookie并删除Cookie的代码:

SET COOKIES:

<?php

...code to get the variables used below (database query)

setcookie("Email", $user_info['Email'], time()+1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("First_Name", $user_info['First_Name'], time()+1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Last_Name", $user_info['Last_Name'], time()+1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Full_Name", $user_info['First_Name']." ".$user_info['Last_Name'], time()+1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("User_Type", $user_info['User_Type'], time()+1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Do_Not_Show_Modals", $user_info['Do_Not_Show_Modals'], time()+1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Org_ID", $user_info['Company_ID'], time()+1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Org_Name", $user_info['Org_Name'], time()+1209600, '/', $_SERVER['SERVER_NAME']);

header("Location: Inside_the_site");
?> 

删除COOKIES

<?php

unset($_COOKIE['Email']);
unset($_COOKIE['First_Name']);
unset($_COOKIE['Last_Name']);
unset($_COOKIE['Full_Name']);
unset($_COOKIE['User_Type']);
unset($_COOKIE['Do_Not_Show_Modals']);
unset($_COOKIE['Org_ID']);
unset($_COOKIE['Org_Name']);
unset($_COOKIE['_ga']);

setcookie("Email", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("First_Name", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Last_Name", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Full_Name", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("User_Type", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Do_Not_Show_Modals", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Org_ID", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);
setcookie("Org_Name", "DELETE", time()-1209600, '/', $_SERVER['SERVER_NAME']);

header("Location: https://www.homepage.com");
?>

0 个答案:

没有答案