問題描述
我已經嘗試在 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 時出現問題,不會取消設置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!