取消设置Cookie php [英] Unset cookies php

查看:202
本文介绍了取消设置Cookie 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(
isset($ _ POST [remember_me])&&
$ _POST [remember_me] == 1&&
$ _COOKIE ['pass']!= NULL&
$ _COOKIE ['email']!= NULL&&

pre>

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 name

setcookie('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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆