如何使用 PHP 获取浏览器 cookie 列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9403614/
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
How to get a list of browser cookies using PHP?
提问by rexposadas
From my understanding $_COOKIE
gives me all the cookies in a user's browser.
根据我的理解$_COOKIE
,我提供了用户浏览器中的所有 cookie。
But when I do
但是当我这样做时
var_dump($_COOKIE);
I get the following:
我得到以下信息:
Array
(
[wp-settings-1] => m8=o&m2=o&m5=o&m4=o&m3=o&m1=o&m7=o&m0=o
[wp-settings-time-1] => 1329859655
[PHPSESSID] => ST88bLB7PE5S9BbY5oXxLgDIcas
)
This list does not match the list I see in the browser. For example, PHPSESSID is not in the list of cookies in my browser. Am I accessing the wrong variable?
此列表与我在浏览器中看到的列表不匹配。例如,PHPSESSID 不在我浏览器的 cookie 列表中。我是否访问了错误的变量?
Thanks.
谢谢。
采纳答案by Rob
As mentioned $_COOKIE
only gives you cookies for the current domain/path. You cannot see all cookies in a browser. You can see how this works if you ever sniff/view HTTP packets. When you make an HTTP request, the browser sends cookies to the server. This pagehas some excellent examples of what that HTTP traffic looks like.
如前所述,$_COOKIE
只为您提供当前域/路径的 cookie。您无法在浏览器中看到所有 cookie。如果您曾经嗅探/查看 HTTP 数据包,您可以看到它是如何工作的。当您发出 HTTP 请求时,浏览器会将 cookie 发送到服务器。这个页面有一些关于 HTTP 流量是什么样子的很好的例子。