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

來源:互聯網
上載者:User

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.

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.