Home > Common Problem > What is the function of cookies?

What is the function of cookies?

coldplay.xixi
Release: 2020-11-02 11:32:00
Original
26242 people have browsed it

Function of cookies: 1. Cookie is a plain text file saved on the client; 2. Cookie files must be supported by the browser, and cookies can be blocked in the browser.

What is the function of cookies?

Function of cookie:

Cookie is a plain text file saved on the client. For example, txt file. The so-called client is our own local computer. When we use our own computer to access a web page through a browser, the server will generate a certificate and return it to my browser and write it to our local computer. This certificate is a cookie. Generally speaking, cookies are plain text files written by the server to the client. Let's take a look at the cookie files that general websites write to us as follows:

Cookie files must be supported by the browser, and the browser can be set to block cookies. In this way, the server cannot write cookies to the client. Currently, most browsers support cookies. Such as Google, IE, Firefox, etc. Generally speaking, cookies cannot be blocked, because sometimes cookies must be used when accessing a website. Otherwise the website will not be accessible.

So, here comes the problem, what exactly do we use this thing for?

For example, if we go to the website to buy something, I open the web page for buying shoes. At this time, I send a request and tell the server that you will return me some shoe information and list. At this time, the client The connection to the server is disconnected.

The user visited again and added a pair of shoes to the shopping cart and then the connection was disconnected. At this time, the user wants to buy a pair of pants again, and the user also adds the pants to the shopping cart. At this time, the connection is disconnected again. At this point, the user sends another request saying, I want to check out, and then the user opens a new checkout interface. Now the question is, how does the server know the items in the shopping cart that the user just added? How does the server know that this user bought something?

So now cookies are used. Before the emergence of seesion, most websites save requested content through cookies, and the server displays specific content based on the user. That is to say, if we do not use cookies, we will not be able to see the items in the shopping cart in the browser. This is similar to the browser's favorites. If we have collected it, we will see our collection next time we open the browser window. s things. In other words, the cookie saves a before and after state. If I don't use cookies, I won't know whether I have added it to the shopping cart. So why does this happen? In the final analysis, it is because of the connectionless nature of http.

Related learning recommendations: Programming video

The above is the detailed content of What is the function of cookies?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template