What is a Cookie

     

CookieTraditionally a snack eaten with milk. On the Internet, however, the word “Cookie” has taken on an entirely different meaning. So what exactly is a “Cookie”?

A “Cookie” is a small amount of information that is sent by a web server to be stored in a web browser so that it can be read back from that browser the next time the unique visitor returns to the web server.

This is useful to let the browser remember specific information about the visitor, such as the last location visited, the time spent, or user preferences (such as style sheets). A Cookie is a text file stored in the browser directory and stored in RAM while the browser is running. Cookies can also be stored on your computer’s hard drive once you log out of the site or web server. All cookies are terminated when the visitor ends his browser conversation.

\

Again, a quick understanding of cookies

         

Cookie: a small piece of text, plain text. Stored in the client’s browser memory or on disk. The disk storage location varies according to the browser. It is a client-side state retention mechanism, (website data is stored in the client), and hidden fields and ViewState objects belong to this kind of client-side state retention, cookies are stored in the text string data related to the website, cookies are related to the website, baidu can write cookies to the client, Sina can also write cookies, but Baidu can only read with Baidu website related cookies.

Cookie will be sent to the background with the request website [if the request baidu, then put baidu’s cookie in the request packet inside, and then sent to the background.





Cookies can be set to a Path that restricts pages below a Path from sending cookies to the background.

For example: request a picture, request a CSS, JS, in order to improve performance, you can set the path of the page through the path, to control the sending of cookies.

The Cookie domain

When the browser sends data to the background, it puts the cookie in the request message and sends it to the background. So the question is: the request is the web page of the subdomain, so will the cookie of the primary domain be sent to the background? Answer: Yes. Send a block. Subdomain cookies are not sent to the background if the request is made to the primary domain page. If the subdomain wants requests for the primary domain page to be sent to the background as well, the primary domain can be set to the current Cookie.

Cookies are written to the foreground in the form of response packets. Cookies are finally written in response headers and cookies are limited (most browsers)

How cookies are stored

Cookies can be stored in two ways: if the expiration time is not specified, they are stored in the browser memory of the client; if the expiration time is specified, they are stored on the disk of the client. Cookies are related to specific websites. If we set the expiration time for cookies, when users visit our website within the specified time, the Cookie data belonging to our website will be sent in request packets, while cookies of other websites will not be sent.

Functions and features of cookies

Setting cookies on the same page is actually done from back to front. If you want to delete a Cookie first and then write a Cookie, you must write a write statement first and then write a delete statement; otherwise, an error occurs.

Cookies are path-oriented. With the default path property, the Web server page automatically passes the current path to the browser, forcing the server to use the set path. Cookies set on one directory page are not visible on another directory page.

Cookies must be set before the content of the HTML file is output; Cookies are handled differently by different browsers (Netscape Navigator, Internet Explorer). If a client user disables cookies, cookies cannot be created. On the client, a browser can create a maximum of 300 cookies, and each Cookie cannot exceed 4KB. Each Web site can set a maximum of 20 cookies.

Application scenarios of cookies

For example, every anonymous user can browse jingdong products, but the background of Jingdong will not keep records of all people browsing, because there are too many. So cookies are used, keeping records only on each user’s client.

There are three features of shopping cart: 1. The goods can be distinguished by their owner; 2. 2, can be stored; 3. You can add goods without logging in.

Cookie information of the browser