What is a cookie? How does cookie work?

A cookie is a piece of text that a Web server can store on a user's hard drive. Cookies allow a website to store information on a user's computer and then retrieve it. Information pieces will be saved as name-value pairs (name-value).

Network administration - Cookies are a very simple thing but they are very useful for navigating the web . Most website designers use them because they can bring a better user experience and make it easier to collect accurate information about visitors of the site.

In this article, we will introduce you to the basic cookie techniques as well as some of the features they allow.

What is a cookie?

There is a definition somewhere that I have read about the Cookie definition as follows: A cookie is a program that websites place on your hard drive. They will be in the computer and collect information about you and everything you do on the Internet, whenever the website wants it, it can download all the information the cookie has collected.

The above definition is completely wrong. The real problem is, Cookie is not a program, they cannot run the same way that programs still run. Therefore, they cannot collect information about their owners. They also cannot collect any personal information about you from your computer.

This is a valid definition of Cookie: A cookie is a piece of text that a Web server can store on a user's hard drive. Cookies allow a website to store information on a user's computer and then retrieve it. Information pieces will be saved as name-value pairs ( name-value ).

For example, a website may create a unique ID number for each visitor and store that ID number on each user's computer with a cookie file.

If you use Microsoft's Internet Explorer to browse the web, you can see all cookies stored on your computer. The location they normally reside in is in the directory named c: windowscookies . When you look at that folder on your computer, you will see lots of files. Each file is a text file containing name-value pairs and a file for each website that has set a cookie on your computer.

You can see in the directory that these files are very simple, they are regular text files. You can see which website has placed the file on your computer by observing the file name (the information is also stored inside the file). You can open each file by clicking on it.

For example, we visited goto.com , and this site placed a cookie on my computer. The cookie file for goto.com includes the following information:

 UserID A9A3BECE0563982D www.goto.com/ 

Goto.com has saved on my computer a name-value pair. The name of the value is UserID , and the value is A9A3BECE0563982D . When I first visited goto.com, the site gave me a unique ID value and saved it on my computer.

( Note that there may be other values ​​stored in the file. These are "butler" information for the browser ).

Amazon.com stores more information, when observing the cookie file that Amazon has created on my computer, it includes the following:

 session-id-time 954242000 amazon.com/ 
session-id 002-4135256-7625846 amazon.com/
x-main eKQIfwnxuF7qtmX52x6VWAXh @ Ih6Uo5H amazon.com/
ubid-main 077-9263437-9645324 amazon.com/

It shows that Amazon stores a user ID and an ID for each session, and the session time is started on my computer.

Most sites only store one piece of information - user ID - on your computer. However, a site can store multiple name-value pairs if it wants to.

A name-value pair is simply a named piece of data. It is not a program, cannot do anything. A website can only retrieve the information it has placed on your computer. It cannot retrieve information from other cookie files, nor can it get other information from your computer.

How is cookie data transferred?

As you can see in the previous section, cookie data is simply name-value pairs saved by the website on your hard drive. That's all cookie data. Websites store data and then retrieve it. A website can only receive data that it has saved on your computer. It cannot look at other cookies or anything on your computer.

What is a cookie? How does cookie work? Picture 1What is a cookie? How does cookie work? Picture 1
When you type a url into your browser, the web server can look in your filecookie

Data is transmitted as follows:

- If you type the URL of a website into the address bar, the browser will send a request to the website. For example, if you enter the URL https://quantrimang.com into your browser, the browser will contact the network administrator's server and request its home page.

- When the browser does this, it will search your computer for the cookie file that the Network Administrator has set up. If it finds a cookie file of the Network Administrator, the browser will send all name-value pairs in the file to the Network Administrator's server with the URL. If it is not found, it will not send cookie data.

- The network administrator's Web server will receive cookie data and requests for the home page. If the pair receives name-value pairs, network administrators can use them.

- If no name-value pairs are received, the Network Administrator knows that this is the first time you have access to this website. Its server will create a new ID for you in the Network Administrator database and then send name-value pairs to your computer in the header for the website it will send. Your computer will store these name-value pairs on your hard drive.

- Web server can change name-value pair or add new pairs whenever you access the site and request the page.

There are many other pieces of information that the server can send with name-value pairs. One of them is the expiration date expiration date . Another is path path (so the site can associate cookie values ​​with other parts of it).

You can control this process. You can set options in your browser so that the browser notifies you when the site sends name-value pairs. You can then accept or reject these values.

How do websites use cookies?

Cookies are opened because they solve a big problem for website executives. In the broadest sense, a cookie allows a site to store status information on your computer. This information allows a website to remember what your browser status is. ID is a piece of state information - if an ID exists on your computer, the site knows that you have accessed it before. The status is, 'Your browser has accessed the site at least once' and the site knows the ID from that visit.

Websites use cookies in different ways. These are some of the most commonly used cases:

- Site can accurately determine the number of visitors to the site. The only way for a site to accurately count visitors is to set a cookie with a unique ID for each guest. Using cookies, sites can identify:

    1. How many visitors come
    2. How many new visitors and repeat visitors.
    3. How often a visitor goes to the page.

The way a website can do this is by using a database. The first time a visitor arrives, the site will create a new ID in the database and send the ID as a cookie. The next time the user accesses again, the site can increase the count associated with the ID in the database and know the number of times visitors visit the site.

- Site can save user preferences to make a difference between visitors (it can be said that the website allows you to customize). For example, if you access msn.com , it will give you the ability to change the content, interface and colors. It also allows you to enter the zip code and can receive regional weather forecast information. When you enter the zip code, the following name-value value will be added to MSN's cookie file.

 WEAT CC = NC% 5FRaleigh% 2DDurham®ION = www.msn.com/ 

- E-commerce sites can perform other tasks such as shopping cart and payment options. The cookie will contain an ID and allow the site to keep in touch with you when you need to add other things to your shopping cart. Each of the things you add to your shopping cart is stored in the site database along with your ID value. When you pay, the site knows what is in your shopping cart by retrieving all the necessary information from the database. It would not be possible to implement a convenient shopping mechanism without cookies or something like them.

In all of these examples, note that what the database can save is what you have chosen from the site, the page you have viewed, the information you provided to the site on online forms. , . All of this information is stored in the site's database and in most cases, the cookie includes a unique ID that is all stored on your computer.

Problems with cookies

Cookies are not a perfect mechanism, but they allow you to do some things without them being impossible. Here are some things that make cookies imperfect.

- Regular users share computers - Any computer used in public and computers used in office or home environments, shared by many users. Let's assume you use a shared computer (for example in a library) to buy something online. The website you buy will leave a cookie on that computer and the computer user will be able to buy something from the site where you use your account to shop. Shopping sites often warn about this problem and that's why. Even errors can occur. For example, I have a friend who once used his wife's computer to buy an item on Amazon. Then when his wife accessed Amazon and accidentally clicked the "one-click" button without realizing that she had taken a book purchase with that click.

Something like a Windows NT computer or a UNIX computer using accounts correctly, this doesn't matter. Accounts will separate user cookies. However, in other operating systems they do not allow this, this is really a serious problem.

- Cookies deleted - If you have problems with your browser and call for technical support, make sure the first thing that technical support will require you to do is delete all temporary Internet files on your computer. his calculation. When you do this, you will lose all cookie files. Now, when you re-visit the site, the site will think you are a new user and will assign you a new cookie. This falsifies the site's record of the number of new visitors and return visitors, and it also makes it difficult for you to recover previously saved preferences. This is why the site requires you to register in some cases - if you register with a user name and password, you can log in, even if you lose your cookie file you can still restore it. be the hobby. If preference values ​​are saved directly on the computer (such as the MSN weather forecast example above), recovery is not possible. This explains why many sites store all user information in a database and only store the ID value on the user's computer.

- Multiple computers - Many users often use multiple computers in one day. For example, I have a machine in the office, a home machine and a laptop to go on business occasionally. Unless the site is designed to fix this problem, I will have three cookie files on these three computers. Any site I visit from all three computers will identify me as three completely different users. This can be a problem in setting preferences. Now a site that allows you to register and save interests will allow the same account to be used on all three machines, but site developers must plan for this issue from design.

If you access the URLs as demonstrated in the previous section from a computer and then try to access again from another computer, you will see the history list is completely different. This is because the server has created two IDs for you, one for each machine.

Certainly it will not be easy to solve the above problems, except to require users to register and save everything in the centralized database.
When you register with a registration system of the website, the problem will be solved in the following way:

The site will remember your cookie value and save it with your registration information. If you take a moment to log in from any computer (or a computer has lost cookie files), the server will change the cookie file on that computer to contain the relevant ID with the information. Your registration. So you can have multiple computers with an ID value.

Cookies on the Internet: Privacy issues

If you've read this, you're sure to wonder why there is such a reaction in public opinion about cookies and Internet privacy. You saw in this article that cookies are just text files and also find that they provide a lot of usefulness on the web.

However, two things have caused a strong reaction in the public opinion about cookies:

- The first is what has been bothering customers for years. Let's assume you buy something by mail order method. The supplier company will have your name, address and phone number through your order, they will also know what items you have purchased. The company can then sell that information to another company, which also wants to sell similar products to you. That is the source of remote marketing and spam.

On a website, a site not only tracks your purchases, but it also knows the pages you have read, the ads you have clicked, etc. If you later buy something and enter the address and name. My site will know more about you. This makes the goal more accurate and also makes many people uncomfortable.

- The second issue is the unique to the Internet. There are some infrastructure providers that can create visual cookies on multiple sites. DoubleClick is the most famous example of this. Many companies use DoubleClick to serve banner advertising on their sites. DoubleClick can place small image files (1x1 px) on the site to allow it to load cookies on your computer. DoubleClick can then track your actions across multiple sites. It can see the search string you have typed into the search engine. Because it can collect so much information about you from multiple sites, DoubleClick can create very rich profiles. This is very similar to spying and it is also the cause of the reaction.

4 ★ | 1 Vote