删除 cookie 时出现问题,不会取消设置 [英] Problems deleting cookies, won't unset

查看:22
本文介绍了删除 cookie 时出现问题,不会取消设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试在 php 手册和互联网上搜索有关如何删除 cookie 的内容,并且我已经按照他们所说的完全相同的方式进行了尝试:

I've tried searching the php manual and internet on how to delete cookies and I've tried it the exact same way they all say:

setcookie("name", '', 1);

setcookie("name", '', time()-3600);

但是当我在 Firefox 的 cookie 对话框中检查 cookie 时,它​​仍然具有相同的值.我使用以下行设置此 cookie:

But when I check the cookies in the cookies dialog in Firefox, it's still there with the same value. I set this cookie using the following line:

setcookie("name", $value, time() + 259200, $path);

我在 stackoverflow 上发现了这个问题:,但没有一个答案解决了问题.我也试过把所有参数都放进去,就像作者说的那样,但没有效果.

I found this question on stackoverflow: , but none of the answers solved the problem. I also tried putting all paramaters in, like the author said, but it had no effect.

有人看到问题了吗?

推荐答案

手册说明:

必须使用与设置时相同的参数来删除 Cookie.如果 value 参数是一个空字符串,或者 FALSE,并且所有其他参数都与之前对 setcookie 的调用匹配,那么具有指定名称的 cookie 将从远程客户端中删除.这是通过将值设置为已删除"并将过期时间设置为过去一年来在内部实现的.

Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.

所以还要确保 $path 被正确指定——删除它时也是如此.例如,如果 cookie 是在子目录中指定的,您可能无法从父目录或子目录(或两者)中删除它.

So also make sure that $path is specified correctly -- also when deleting it. For instance, if the cookie was specified in a subdirectory, you may not be able to delete it from either the parent or children directories (or both).

我不完全确定权限是如何工作的,但您可能希望使用 Web 开发人员工具栏查看您尝试删除的 cookie 的路径.

I'm not entirely sure how the permissions work, but you might want to use the Web Developer Toolbar to view what the path is of the cookie you are attempting to delete.

这篇关于删除 cookie 时出现问题,不会取消设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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