代码改变世界

IE or Chrome can not use localhost, firefox can works.

2013-09-12 16:05  蜡笔小旧  阅读(697)  评论(0编辑  收藏  举报

因为服务器开启'localhost:9999",使用IE无法登陆,firefox下正常。

遂查看cookie,果然没有写入。

stackoverflow.com:

"ie enable cookies for localhost"

"ie localhost not working"

一般答案都是重置IE,设置hosts文件:127.0.0.1 localhost,都无法解决问题。

正解:

IEs认为domain name都带‘.’,不能为一级域名,所以hosts文件设置"127.0.0.1 localhost.com",可以解决问题 :)

顺便插一句:很多大型网站为了减轻服务器压力,一般把资源文件的cookie domain单独使用一个域名。

 

ref:http://stackoverflow.com/questions/7346919/chrome-localhost-cookie-not-being-set

Cookies are designed for second level and down. First level domains will not work. Instead you should use the address http://127.0.0.1 (as you mentioned) or you could edit your hosts file to map a different URL with a TLD to the address 127.0.0.1 such as:

yoursite.tld   127.0.0.1

Just researched this further; found this answer: Cookies on localhost with explicit domain