成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Cookie的理解

1》cookie詳解


什么是cookie

An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to the user's web browser. The browser may store it and send it back with the next request to the same server. Typically, it's used to tell if two requests came from the same browser — keeping a user logged-in, for example. It remembers stateful information for the stateless HTTP protocol.

創(chuàng)新互聯(lián)是一家專業(yè)提供莒南企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、HTML5、小程序制作等業(yè)務(wù)。10年已為莒南眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。

     cookie(“小甜餅”)就是服務(wù)器發(fā)送到我們web瀏覽器的一小塊數(shù)據(jù)。瀏覽器會(huì)存儲(chǔ)它并且當(dāng)下次再訪問(wèn)同一個(gè)網(wǎng)站,web服務(wù)器會(huì)先看看它上次有沒有他上次留下的cookies資料,有的話會(huì)依據(jù)cookie里的內(nèi)容來(lái)判斷使用者,送出特定的網(wǎng)頁(yè)內(nèi)容給你。


cookie的三大作用

-Session management
     logins,shopping carts,game scores,or anything else the server should remember

-Personalization(個(gè)性化設(shè)置)
     User preferences,themes,and other settings

-Tracking
     Recording and analyzing user behavior


Create Cookies (創(chuàng)建cookie)

When receiving an HTTP request, a server can send a Set-Cookie header with the response. The cookie is usually stored by the browser, and then the cookie is sent with requests made to the same server inside a Cookie HTTP header. An expiration date or duration can be specified, after which the cookie is no longer sent. Additionally, restrictions to a specific domain and path can be set, limiting where the cookie is sent.

    當(dāng)服務(wù)器接收到一個(gè)http請(qǐng)求時(shí)會(huì)發(fā)送一個(gè)Set-Cookie的響應(yīng)頭,這cookie通常會(huì)被瀏覽器存儲(chǔ),并且這cookie會(huì)被寫在訪問(wèn)同一個(gè)服務(wù)器的http請(qǐng)求頭中。此外,我們使用了cookie的一些屬性來(lái)限定cookie的使用。例如Domain屬性能夠在瀏覽器端對(duì)cookie發(fā)送進(jìn)行限定;Expires屬性則指定了該Cookie保存的時(shí)間限制;屬性Path,則用來(lái)指定Cookie將被發(fā)送到服務(wù)器的哪一個(gè)目錄路徑下。

The Set-Cookie and Cookie headers

Set-Cookie 的響應(yīng)頭會(huì)從服務(wù)器端發(fā)送cookie到瀏覽器端。

HTTP/1.0 200 OK
Content-type: text/html
Set-Cookie: yummy_cookie=choco
Set-Cookie: tasty_cookie=strawberry

[page content]

現(xiàn)在每個(gè)新的請(qǐng)求,瀏覽器會(huì)利用cookie 頭把所有先前存儲(chǔ)的cookies發(fā)送到服務(wù)器。

GET /sample_page.html HTTP/1.1
Host: www.example.org
Cookie: yummy_cookie=choco; tasty_cookie=strawberry

Session cookie

上面的cookie是一個(gè)session cookie:當(dāng)客戶端關(guān)閉時(shí)它會(huì)被刪除。因?yàn)樗鼪]有指定Expires或Max-Age指令。但是,Web瀏覽器可能會(huì)使用會(huì)話還原,這會(huì)使大多數(shù)會(huì)話cookie永久保留,就像瀏覽器從未關(guān)閉一樣。

Permanent cookie

永久cookie只會(huì)在特定的時(shí)間過(guò)期而不是在客戶端關(guān)閉時(shí)過(guò)期

Set-Cookie: id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT;

Secure and HttpOnly cookies

安全cookie僅通過(guò)HTTPS協(xié)議通過(guò)加密請(qǐng)求發(fā)送到服務(wù)器。但是盡管安全,重要的東西還是不能放在cookie中。為了防止跨站點(diǎn)腳本(XSS)***,JavaScript的Document.cookie API無(wú)法訪問(wèn)HttpOnly cookie;它們只被發(fā)送到服務(wù)器。

Set-Cookie: id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly

Scope of cookies(cookies 范圍)

Domain和Path指令定義cookie的范圍:cookie應(yīng)發(fā)送到哪些URL。
Domain指定允許的主機(jī)接收cookie。如果未指定,則默認(rèn)為當(dāng)前文檔位置的主機(jī),不包括子域。如果指定了域,則始終包含子域。
例如,如果設(shè)置了Domain = mozilla.org,則cookie將包含在developer.mozilla.org等子域中。
Path表示在請(qǐng)求的URL中必須存在的URL路徑,以便發(fā)送Cookie標(biāo)頭。 %x2F(“/”)字符被視為目錄分隔符,子目錄也將匹配。
For example, if Path=/docs is set, these paths will match:

/docs
/docs/Web/
/docs/Web/HTTP     

分享標(biāo)題:Cookie的理解
分享URL:http://jinyejixie.com/article8/iejhop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計(jì)、微信小程序、網(wǎng)站制作、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)
繁峙县| 阜阳市| 都匀市| 黄石市| 乌鲁木齐县| 马山县| 土默特右旗| 张家界市| 黎城县| 光山县| 光山县| 双鸭山市| 陆丰市| 陆丰市| 南雄市| 东辽县| 当雄县| 南康市| 米泉市| 监利县| 大石桥市| 镇江市| 景宁| 康马县| 大丰市| 湘阴县| 林西县| 仙游县| 新兴县| 桃源县| 德格县| 古浪县| 弥渡县| 嘉义市| 香港 | 陇川县| 重庆市| 白沙| 平陆县| 盖州市| 枣强县|