宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

今天在本地调试代码的时候,再域名中使用localhost,结果一直调试不成功,最后发现在登录时,setcookie()没有设置进去

于是发现了,在使用localhost调试时,保存cookie是无效的。记录一下。

原因:手册里关于setCookie说了,域名要有至少两个点,你用127.0.0.1都可以。否则就会被浏览器拒绝。

   手册原文:
domain names must contain at least two dots (.),
hence ‘localhost’ is invalid and the browser will refuse to set the cookie!
instead for localhost you should use false
 解决:直接使用127.0.0.1      或者    自己定义一个域名,在host中做映射