標籤:cookie ie domain
前兩天,在測試伺服器上通過配置host來測試系統,發現在IE下面cookie的讀寫存在問題,一開始以為是代碼和架構的問題,於是寫了一個最簡單的PHP頁面來讀寫,發現依然不行。通過fiddler抓包軟體發現cookie確實有正常的傳輸,說明網路是OK的。後來懷疑是php配置的問題,於是將PHP語言轉換為JS來讀寫COOKIE,發現依然不行。後來無意中一個測試的同事通過網域名稱直接存取,在IE下的cookie讀寫正常,於是懷疑是網域名稱中有特殊的字元因為了IE對cookie解析的異常。經過排查,發現網域名稱中帶有“_”的網域名稱都會引起IE cookie異常。將_去掉,一切正常。最後通過尋找資料發現如下的資訊:
According to RFC1035 (Domain names - implementation and specification):
[domain names] must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen.
Turns out some of the domains had an underscore ( "_" ) in them: some_domain.example.com. Although this is a violation of the RFC, all other browsers work normally.
MSIE 7, on a domain with an underscore, silently drops all cookies for that host and refuses to accept new ones.
The only solution is to use RFC-compliant domains (I‘ve replaced all the "_"s with "-"s and set up a RewriteRule so that traffic is redirected to the compliant domains).
根據RFC1035規則,網域名稱的實現和規範必須以字母開頭,以字母或者數字結束,其他的部分必須數字,字母或者連字號-。
同時提到msie7,網域名稱中包括_,將會丟棄掉所有的cookie並拒絕接受新的。