取消设置Cookie php [英] Unset cookies php
问题描述
我有这个代码,当登录检查是正确的:
if((isset($ _ POST [remember_me ])&&($ _ POST [remember_me] == 1))
{
setcookie('email',$ username,time()+ 3600);
setcookie('pass',$ pass,time()+ 3600);
}
现在,当我点击注销链接(logout.php)
i这样做:
<?php session_start
setcookie(email,'',1,);
setcookie(pass,'',1,);
$ _SESSION [login] =;
header(location:aforum / enter_furom.php);
?>
我没有使用destroy会话,因为我不想销毁所有会话....
现在破坏会话是正常工作...但是当我尝试取消设置cookie,浏览器(所有浏览器:explorer,chrome,firefox,mozilla)给我一个错误,说明新的cookie不能已设定 ...任何帮助取消设置上述Cookie?
使用超级全局 _COOKIE
变量:
unset($ _ COOKIE ['mycookiename']);
或调用 setcookie()
>仅 Cookie名称
setcookie('mycookiename');
要在注销时重置Cookie:
setcookie('pass');
setcookie('email');
对于您的登录检查:
if(
pre>
isset($ _ POST [remember_me])&&
$ _POST [remember_me] == 1&&
$ _COOKIE ['pass']!= NULL&
$ _COOKIE ['email']!= NULL&&
)
I have this code that setted when login check is fine:
if((isset($_POST["remember_me"]))&&($_POST["remember_me"]==1)) { setcookie('email', $username, time()+3600); setcookie('pass', $pass, time()+3600); }
Now, when I click on logout link (logout.php) i did this:
<?php session_start(); setcookie("email", '', 1, ""); setcookie("pass", '', 1, ""); $_SESSION["login"] = ""; header("location: aforum/enter_furom.php"); ?>
I didn't use destroy session because I don't want to destroy all sessions.... now destroying a session is working fine... but when I try to unset cookies, the browsers (all browsers: explorer, chrome, firefox, mozilla) give me an error saying that the new cookies cant be setted...any help to unset the above cookies ?
解决方案either use the superglobal
_COOKIE
variable:unset($_COOKIE['mycookiename']);
or call
setcookie()
with only the cookies namesetcookie('mycookiename');
To reset your cookies at logout use:
setcookie('pass'); setcookie('email');
For you login check:
if( isset($_POST["remember_me"]) && $_POST["remember_me"]==1 && $_COOKIE['pass'] != NULL && $_COOKIE['email'] != NULL && )
这篇关于取消设置Cookie php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!