现在的位置: 首页 > 综合 > 正文

IE下COOKIE失效的一种特殊情况

2013年09月18日 ⁄ 综合 ⁄ 共 1106字 ⁄ 字号 评论关闭

setcookie ("name",
"value",
0, "/",
".example.com");

使用以上代码设置cookie后,在非IE(chrome、firefox等)下访问 test_1.example.com 均可正常获取;使用IE访问则获取不到该cookie。

访问 test.example.com 任何浏览器均可正常获取。

本来以为是setcookie参数问题,后来以为是两套代码不同问题,发现都不是。

最后发现是域名问题:域名中不能含有“_”(下划线)。。。

------------------------------我是分割线-------------------------------

RFC 952 有明文规定
 
 A "name" (Net, Host, Gateway, or Domain name) is a text string up to 24 characters drawn from the
alphabet (A-Z), digits (0-9), minus sign (-), and period (.) .

Note that periods are only allowed when they serve to delimit components of "domain style names". (See RFC-921, "Domain Name System Implementation Schedule", for background). No blank or space characters are permitted as part of a name. No distinction is made
between upper and lower case. The first character must be an alpha character. The last character must not be a minus sign or period. A host which serves as a GATEWAY should have "-GATEWAY" or "-GW" as part of its name. Hosts which do not serve as Internet
gateways should not use "-GATEWAY" and "-GW" as part of their names. A host which is a TAC should have "-TAC" as the last part of its host name, if it is a DoD host. Single character names or nicknames are not allowed.

虽然很多网站,甚至是某些知名网站的一些二级域名仍有采用这种不规范命名,但大家在平时使用中还是最好应尽量避免使用带有下划线的域名。

抱歉!评论已关闭.