javascript 如何使用 PHP 或 JS 通过 HttpOnly 删除 cookie

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33528579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2021-01-28 16:35:47  来源:igfitidea点击:

How to delete cookie with HttpOnly using PHP or JS

javascriptphpcookiescookie-httponly

提问by anton2g

I have a cookie with these parameters:

我有一个带有这些参数的 cookie:

Name:   workgroup_session_id
Content:    ""
Domain: agrobman1.tsi.lan
Path:   /
Send for:   Any kind of connection
Accessible to script:   No (HttpOnly)
Created:    Wednesday, November 4, 2015 at 9:31:58 AM
Expires:    When the browsing session ends

I have tried to delete the cookie using PHP using this code:

我尝试使用以下代码使用 PHP 删除 cookie:

setcookie("workgroup_session_id", "\"\"", time() - 3600, "/", "agrobman1.tsi.lan", false, true);

But I am still unable to delete it. Does anyone know how to delete a cookie of this type using PHP or JS?

但我仍然无法删除它。有谁知道如何使用 PHP 或 JS 删除这种类型的 cookie?

回答by Andrew

You cannot delete an HttpOnly cookie on the client-side with javascript, as this postpoints out. It has to be done on the server side, as Neta points out.

正如这篇文章指出的那样,您不能使用 javascript 删除客户端上的 HttpOnly cookie 。正如 Neta 指出的那样,它必须在服务器端完成。