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.
雖然很多網站,甚至是某些知名網站的一些次層網域仍有採用這種不規範命名,但大家在平時使用中還是最好應盡量避免使用帶有底線的網域名稱。