$_SERVER['HTTP_COOKIE'] return's two PHPSESSID

匆匆过客 提交于 2019-12-07 10:34:48

问题


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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!