php $_server http_cookie,$_SERVER['HTTP_COOKIE'] return's two PHPSESSID

在本地系统中,发现HTTP_COOKIE头中有两个PHPSESSID,这通常是由于设置了不同Path或Domain的cookie导致的。RFC6265规定服务器不应依赖于Cookie头中相同名称的cookie出现的顺序。$_COOKIE变量只会存储其中一个值。
摘要由CSDN通过智能技术生成

问题

I am getting two PHPSESSID while printing $_SERVER['HTTP_COOKIE']. Actually I don't know how it is set twice, its only in my local system.

When I check the SERVER cookie it like:

echo $_SERVER['HTTP_COOKIE'];

//result

'fe_toolbar=false;

fe_toolbar=false;

PHPSESSID=4tvbovcjk0msf9dvibeb31c2b7;

langId=1;

backendLangId=2;

PHPSESSID=46aagg1hg7as2uh9bihjlpp8h7'

When I check my cookie alone like :

print_r($_COOKIE);

//result

array (

'fe_toolbar' => 'false',

'PHPSESSID' => '4tvbovcjk0msf9dvibeb31c2b7',

)

回答1:

You can have multiple cookies with the same name. This happens when you set cookie with different Path or Domain attributes. They are all send to the server.

a8d8faee4f352b31a04ff1c0223c906d.png

The RFC 6265 specific

if the Cookie header contains two cookies with the same name (e.g.,

that were set with different Path or Domain attributes), servers SHOULD NOT rely upon the order in which these cookies appear in the header.

Your $_COOKIE will be populated with one of these values.

来源:https://stackoverflow.com/questions/30934854/serverhttp-cookie-returns-two-phpsessid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值