douzou7012 2018-12-05 22:36
浏览 118

php setcookie,域名没有正确限制在chrome但是在Firefox中

I'm setting a cookie in php:

 setcookie('testcookie[test_id]', "testvalue", (time()+(60*60*24*31)), "/", ".".$_SERVER['SERVER_NAME'],"1");

My live site domain value is like ".examplelive.com" and the test site is similar but shorter, e.g. ".example.com".

Here is the funny thing: The cookie is set fine, both on my testing server and live server. On my testing server, I can see both cookies, the cookie is duplicated!

So, for example when I navigate from my live server to my testing server, the cookies is duplicated and I can see both live and testing versions when browsing the test stie in Chrome. In FireFox, I only see one copy of the cookie in either site, which is desired result.

I have an entry in /etc/hosts on my machine to direct ".example.com" to my test site.

So, am I doing something wrong in how I'm setting cookies, or is this a quirk of Chrome?

  • 写回答

1条回答 默认 最新

  • duanjiashai9140 2018-12-06 13:26
    关注

    Thanks to Barmar for pointing out the possibility of the test site loading a resource (e.g. image) from the live site. That was indeed what was happening and I'd missed it.

    Interestingly, the difference in Chrome vs. FireFox in how 'inspect' shows cookies remains. The cookie from the live site shows under the test domain when 'inspect'ing cookies in Chrome, but not FireFox.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器