How do websites use your cookies ?
Let’s take a look at how cookies work.
Imagine we have a website that requires people to log in to see the contents of the site. When you log in, your browser sends your user name and password to the server, who verifies them.
If everything is checked out, it sends you the requested content. However, there is a small caveat. The HTTP protocol - which we use to browse the Internet - is stateless. That means that when you make another request to that same server, it has forgotten who you are and will ask you to log in again.
The advantages of cookies
Time-saving
Can you imagine how time-consuming it would be to browse around a site like Facebook and having to log in again every time you click on something?
With the help of cookies, you can still log in to the website, and the server still validates your credentials. If everything checks out, however, the server not only responds with the content but also sends a cookie to your browser.
The cookie is then stored on your computer and submitted to the server with every request you make to that web. The cookie contains a unique identifier that allows the server to remember who you are and keep you logged in.
Login Prsistence
But it doesn’t stop there. Besides keeping you logged in, cookies can also be used to store your setting. Let’s say you change the number of results your favorite search engine should return. Chances are high that they save these preferences on a cookie and not on their servers.
The disadvantages of cookies
Data Constraints
But there are also some restrictions on the use of cookies. Most browsers only allow websites to store a maximum of 300 cookies and they can not contain a lot of data (just 4096 bytes maximum).
The biggest limitation, however, is the fact that cookies set by one website can not be read by another. And that restriction raises the question: How can companies use cookies to track us around the internet?
How can companies use cookies to track us around the internet?
Let's look at the example of how website tracks you through cookies.
The whole process starts when you log into Facebook. To remember you logged in, Facebook stores cookies on your computer, and nothing unusual about that, but many other sites do the same things.
A cookie will be stored on your computer by a website you visit. Each cookie is a small file created by the website you browsed. Since the data in cookies doesn't change, cookies themselves aren't harmful. They can't infect computers with viruses or other malware.
Get back to Facebook example, the Facebook’s cookie is scoped, or bout to Facebook’s domain name, meaning that no one else beside Facebook.com can read what’s on the cookie.
Now imagine that you browse away and you land on someone’s blog. The blog can not read your cookie, and the scope prevents that.
Facebook also can not see that you are in that blog. But what if the blog owner places a Facebook like button on his website. To show this like button, your browser has to download some code from Facebook servers, and when it’s talking to Facebook.com, it sends along the cookies that Facebook set earlier. Facebook now knows who you are and that you visited this blog.
Facebook is just an example here. This technique is used by many other companies to track you around the internet. The trick here is so simple: convincing as many websites as possible to place some of your code on their sites.
Facebook has it easy because lots of people want a like or share buttons on their websites. Google also has an easy job because many websites rely on its advertisement network or on Google Analytics.
But not all these cookies track you around. In fact, a handful of them are essential for the site to work correctly, like a session cookie to remember that you are logged in. However, the majority of cookies on these websites will not serve the users. They are there to track you or to display more targeted ads.