Cookies

### What is cookies?

An **HTTP cookie** (also called **web cookie**, **Internet cookie**, **browser cookie** or simply **cookie**) is a small piece of data sent from a website and stored on the user's computer by the user's web browser while the user is browsing. Cookies were designed to be a reliable mechanism for websites to remember stateful
 information (such as items added in the shopping cart in an online store) or to record the user's browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past). They can also be used to remember arbitrary pieces of information that the user
previously entered into form fields such as names, addresses, passwords, and credit card numbers.

Other kinds of cookies perform essential functions in the modern web. Perhaps most importantly, **authentication cookies** are the most common method used by web servers to know whether the user
 is logged in or not, and which account they are logged in with. Without such a mechanism, the site would not know whether to send a page containing sensitive information, or require the user to authenticate
themselves by logging in. The security of an authentication cookie generally depends on the security of the issuing website and the user's web browser, and on whether the cookie data is encrypted. Security vulnerabilities may allow a cookie's data to be read by a hacker, used to gain access to user data, or used to gain access (with the
user's credentials) to the website to which the cookie belongs (see cross-site scripting and cross-site request forgery for examples).

The tracking cookies, and especially third-party tracking cookies, are commonly used as ways to compile long-term records of individuals' browsing histories – a potential privacy concern that prompted European and U.S. lawmakers to take action in 2011. European law requires all websites targeting European Union member states gain "informed consent" from users before storing non-essential cookies on their device.

### How are cookies used?

#### Session management

Cookies were originally introduced to provide a way for users to
record items they want to purchase as they navigate throughout a website
 (a virtual "shopping cart" or "shopping basket"). Today, however, the contents of a user's shopping cart are usually
stored in a database on the server, rather than in a cookie on the
client. To keep track of which user is assigned to which shopping cart, the server sends a cookie to the client that contains a unique session identifier (typically, a long string of random letters and numbers). Because
cookies are sent to the server with every request the client makes, that session identifier will be sent back to the server every time the user visits a new page on the website, which lets the server know which shopping cart to display to the user. Another popular use of cookies is for logging into websites. When the user visits a website's login page, the web server typically sends the client a cookie containing a unique session identifier. When the user successfully logs in, the server remembers that that particular session
identifier has been authenticated, and grants the user access to its services.

Because session cookies only contain a unique session identifier, this makes the amount of personal information that a website can save
about each user virtually limitless—the website is not limited to
restrictions concerning how large a cookie can be. Session cookies also help to improve page load times, since the amount of information in a
session cookie is small and requires little bandwidth.

#### Personalization

Cookies can be used to remember information about the user in order
to show relevant content to that user over time. For example, a web
server might send a cookie containing the username last used to log into
 a website so that it may be filled in automatically the next time the user logs in.
Many websites use cookies for personalization based on the user's
preferences. Users select their preferences by entering them in a web
form and submitting the form to the server. The server encodes the preferences in a cookie and sends the cookie back to the browser. This
way, every time the user accesses a page on the website, the server can
personalize the page according to the user's preferences. For example,
the Google
 search engine once used cookies to allow users (even non-registered
ones) to decide how many search results per page they wanted to see. Also, DuckDuckGo uses cookies to allow users to set the viewing preferences like colors of the web page.

#### Tracking

See also: Web visitor tracking

Tracking cookies are used to track users' web browsing habits. This can also be done to some extent by using the IP address of the computer requesting the page or the referer field of the HTTP request header, but cookies allow for greater precision. This can be demonstrated as follows:

1. If the user requests a page of the site, but the request contains no

 cookie, the server presumes that this is the first page visited by the user. So the server creates a unique identifier (typically a string of random letters and numbers) and sends it as a cookie back to the browser
 together with the requested page.

1. From this point on, the cookie will automatically be sent by the

browser to the server every time a new page from the site is requested. The server sends the page as usual, but also stores the URL of the
requested page, the date/time of the request, and the cookie in a log file. By analyzing this log file, it is then possible to find out which pages the user has visited, in what sequence, and for how long.

Corporations exploit users' web habits by tracking cookies to collect information about buying habits. The *Wall Street Journal* found that America's top fifty websites installed an average of sixty-four pieces of tracking technology onto computers resulting in a total of 3,180 tracking files. The data can then be collected and sold to bidding corporations.

1. ↑ Vamosi, Robert (2008-04-14). "Gmail cookie stolen via Google Spreadsheets".
2. ↑ Kesan, Jey; and Shah, Rajiv ; *Deconstructing Code*, SSRN.com, chapter II.B (Netscape's cookies), Yale Journal of Law and Technology, 6, 277–389
3. ↑ Kristol, David; *HTTP Cookies: Standards, privacy, and politics*, ACM Transactions on Internet Technology, 1(2), 151–198, 2001 doi:10.1145/502152.502153 (an expanded version is freely available at arXiv:cs/0105018v1 [cs.SE])
4. ↑ Rainie, Lee (2012). Networked: The New Social Operating System. p. 237