码迷,mamicode.com
首页 > 其他好文 > 详细

Cookie and Session

时间:2014-05-26 12:46:47      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:style   c   java   http   a   color   

Cookies are arbitrary pieces of data chosen by the web server and sent to the browser. The browser returns them unchanged to the server, introducing a state (memory of previous events) into otherwise stateless HTTP transactions. Without cookies, each retrieval of a web page or component of a web page is an isolated event, mostly unrelated to all other views of the pages of the same site. Other than being set by a web server, cookies can also be set by a script in a language such as JavaScript, if supported and enabled by the web browser.
Cookie specifications suggest that browsers should be able to save and send back a minimal number of cookies. In particular, a web browser is expected to be able to store at least 300 cookies of four kilobytes each, and at least 20 cookies per server or domain.

Cookie Structure

Browsers are expected to support, at least, cookies with a size of 4KB. It consists of seven components:

  1. Name of the cookie
  2. Value of the cookie
  3. Expiry of the cookie
  4. Path the cookie is good for
  5. Domain the cookie is good for
  6. Need for a secure connection to use the cookie
  7. Whether or not the cookie can be accessed through other means than HTTP (i.e., JavaScript)

The first two components (name and value) are required to be explicitly set.

cookie和session的区别

cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案。

session产生的session_id放在cookie里面,如果用户把cookie禁止掉,是不是session也不能用了呢?禁止掉cookie后,session当然可以用,不过通过其他的方式来获得这个sessionid,比如,可以根在url的后面,或者以表单的形势提交到服务器端。从而使服务器端了解客户端的状态。

某些浏览器在打开多页面时也可能建立独立的session,IE8、Chrome默认都是共享 session的。

Cookie and Session,布布扣,bubuko.com

Cookie and Session

标签:style   c   java   http   a   color   

原文地址:http://www.cnblogs.com/linyx/p/3746778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!