打印$_SERVER [‘HTTP_COOKIE’]时,我得到两个PHPSESSID.实际上我不知道它是如何设置两次的,它只在我的本地系统中.
当我检查它的SERVER cookie时:
echo $_SERVER['HTTP_COOKIE'];
//result
'fe_toolbar=false;
fe_toolbar=false;
PHPSESSID=4tvbovcjk0msf9dvibeb31c2b7;
langId=1;
backendLangId=2;
PHPSESSID=46aagg1hg7as2uh9bihjlpp8h7'
当我单独检查我的cookie时:
print_r($_COOKIE);
//result
array (
'fe_toolbar' => 'false',
'PHPSESSID' => '4tvbovcjk0msf9dvibeb31c2b7',
)
解决方法:
您可以拥有多个具有相同名称的Cookie.当您使用不同的路径或域属性设置cookie时会发生这种情况.它们都发送到服务器.
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.
您的$_COOKIE将填充其中一个值.
标签:php,session,session-cookies
来源: https://codeday.me/bug/20190628/1316508.html