使用localhost调试本地代码,setcookie无效

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

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

 缘由:手册里关于setCookie说了,域名要有至少两个点,你用127.0.0.1均可以。不然就会被浏览器拒绝。dom

   手册原文:
  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中作映射
相关文章
相关标签/搜索