1. 程式人生 > >IE下COOKIE失效的一種特殊情況

IE下COOKIE失效的一種特殊情況

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.

雖然很多網站,甚至是某些知名網站的一些二級域名仍有采用這種不規範命名,但大家在平時使用中還是最好應儘量避免使用帶有下劃線的域名。