What exactly are cookies that websites are using?

807 views

What exactly are cookies that websites are using?

In: Technology

6 Answers

Anonymous 0 Comments

A (browser) cookie is a small piece of information that a webserver can give to your browser to be stored. From then on, each time your browser makes a request to that webserver, it will also send back that cookie.

Why does it do that? Because the World Wide Web uses a [stateless protocol](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol). It means, that every time you load a page, a request is sent to the webserver. The webserver deals with the request, sends back the response and then suffers a severe case of amnesia. The webserver is done with that request and as far as it’s concerned your next request could as well be your first one or someone elses. This design solves a practical problem for the webserver. You see, you never know, if a visitor will ever come back or not. If you’d use a stateful protocol, where the server needs to remember stuff about visitors, how long do you need to store that? When do you know, the information is no longer needed?

Of course, that creates a problem for the browser. If the server always forgets your stuff, how do you implement something like a virtual shopping basket? You add an item, it immediately forgets that item … yea that’s not going well.

Cookies to the rescue:

* Visitor: Hi webshop, please show me your catalogue
* Webshop: Hi visitor! Here’s my catalogue. Btw., you’re visitor “TD45A7”, please remember that
* Visitor: Hi webshop, please add item 254 to my shopping basket. Btw., I’m “TD45A7”
* Webshop: Thanks “TD45A7”, one item added to your shopping basket. You have one item in your basket.
* Visitor: Hi webshop, please add item 634 to my basket. Btw., I’m “TD45A7”
* Webshop: Thanks “TD45A7”, one item added to your basket. You have two items in your basket.

A cooky can contain all kinds of information. A unique visitor number, like in the example above. Or your preferred language so you don’t have to choose the language again next time you visit.

You are viewing 1 out of 6 answers, click here to view all answers.