1. 程式人生 > >HTTP Cookie header 中set-cookie格式

HTTP Cookie header 中set-cookie格式

hour 沒有 ati 腳本 http服務 iat sat 服務 bre

Cookie相關的Http頭

有 兩個Http頭部和Cookie有關:Set-Cookie和Cookie。 Set-Cookie由服務器發送,它包含在響應請求的頭部中。它用於在客戶端創建一個Cookie Cookie頭由客戶端發送,包含在HTTP請求的頭部中。註意,只有cookie的domain和path與請求的URL匹配才會發送這個cookie。
Set-Cookie Header Set-Cookie響應頭的格式如下所示:
Set-Cookie: <name>=<value>[; <name>=<value>]...
[; expires=<date>][; domain=<domain_name>] [; path=<some_path>][; secure][; httponly]
expires=<date>: 設置cookie的有效期,如果cookie超過date所表示的日期時,cookie將失效。 如果沒有設置這個選項,那麽cookie將在瀏覽器關閉時失效。 註意:date是格林威治時間(GMT),使用如下格式表示:
DAY, DD MMM YYYY HH:MM:SS GMT

                        DAY
                            The day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
                        DD
                            The day in the month (such as 01 for the first day of the month).
                        MMM
                            The three-letter abbreviation for the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
                        YYYY
                            The year.
                        HH
                            The hour value in military time (22 would be 10:00 P.M., for example).
                        MM
                            The minute value.
                        SS
                            The second value.


domain=<domain_name> : path=<some_path>: 註:臨時cookie(沒有expires參數的cookie)不能帶有domain選項。 當客戶端發送一個http請求時,會將有效的cookie一起發送給服務器。 如果一個cookie的domain和path參數和URL匹配,那麽這個cookie就是有效的。

一個URL中包含有domain和path,可以參考http://www.w3school.com.cn/html/html_url.asp


secure : 表示cookie只能被發送到http服務器。 httponly : 表示cookie不能被客戶端腳本獲取到。

HTTP Cookie header 中set-cookie格式