饼干插件登陆怎么用
Have you ever wondered that in spite of HTTP being a stateless protocol, when you log in to a website and buy stuff and checkout how the server can identify you uniquely? You might wonder if HTTP is stateless but your state is maintained through your interactions, isn’t this a contradiction? Welcome to world of cookies (not the ones which we can eat, btw :)), one the of primary ways to maintain user state and interaction between the web browser and the web server.
您是否曾经想过,尽管HTTP是无状态协议,但是当您登录网站并购买商品并检查服务器如何唯一地标识您时,您是否会感到好奇? 您可能想知道HTTP是否是无状态的,但是您的状态是通过交互来维护的,这不是矛盾吗? 欢迎来到cookie的世界(不是我们可以吃的cookie,顺便说一句:)),它是维护用户状态以及Web浏览器和Web服务器之间交互的主要方式之一。
Cookies are tid-bits of information stored by the browser on a user’s computer. The information stored in the cookie is used to uniquely identify a user and this information is sent to server with each request so server can make use of it. Cookies can store a variety of data, such as your name, the date of your last visit, shopping cart contents, etc. Cookies stored by one website can not be accessed by other websites, which makes cookies relatively safe to store personal information. Still, it is a good idea not to store sensitive information in them, like passwords and credit card information.
Cookies是浏览器存储在用户计算机上的信息的小知识。 Cookie中存储的信息用于唯一标识用户,并且此信息随每个请求发送到服务器,以便服务器可以使用它。 Cookies可以存储各种数据,例如您的姓名,您的上次访问日期,购物车内容等。一个网站存储的Cookies无法被其他网站访问,这使得Cookies相对安全地存储了个人信息。 不过,最好不要在其中存储敏感信息,例如密码和信用卡信息。
Cookie的生命周期 (The Lifecycle of a Cookie)
Here’s what the lifecycle of a PHP cookie looks like, from baking to eating:
这是从烘烤到食用PHP cookie的生命周期:
![Lifecycle of a cookie alt](https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2012/07/bcookies-01.png)
There are no cookies when the browser connects to particular server for first time. When the request is made to the PHP script, the script makes a call to the setcookie()
function. This causes a Set-Cookie
HTTP header to be sent in the response that contains the name and value of the cookie to be set.
当浏览器首次连接到特定服务器时,没有cookie。 当向PHP脚本发出请求时,该脚本将调用setcookie()
函数。 这将导致在响应中发送Set-Cookie
HTTP标头,其中包含要设置的cookie的名称和值。
When the browser receives the respons