Cookies are very small pieces of code that collect data from your browser and stores it for future use or sends the data back to the server. You might have noticed that when you enter the first letter or your user name to log in to Facebook or Gmail, it provides you an option that might be the ID that you would have used in the past. This is achieved by using a cookie that stores data on your local machine. Thus you don’t have to take the trouble of entering your user name all over again.
Cookies are used for one main purpose - collect and store data.
Tracking the user’s activity and saving the user’s preferences is just an implementation of using the cookies that have stored data. Although cookies breach privacy, they make your life easier by making the web more customized.
The future of cookie is the super cookie that stores data forever, unlike the cookies that are used currently that expire after a time period.
Image Credit: Mindmatrix - Wikipedia
Cookies are used to store data and based on a certain logic or when a condition is met. The data stored in the cookie is used either by the browser or it is sent to the server of the website that you visited. A best example to understand this functionality of the cookie is shopping carts.
When you visit an online store, you use a shopping cart that will list the items that you bought. If your browser crashes, in the absence of cookies, you will have to go through the entire process of adding items to your cart. Worse enough, you might not remember everything that you bought. Cookies solve this scenario by storing data of all the items that you bought so that you don’t have to worry about losing your data.
In fact, the first time ever a cookie was used, it was used as a solution for a problem encountered while developing an online E-Commerce website. The invention of the computer cookie is credited to Lon Montulli when he was working for Netscape Communications.
Now that you have very good understanding of how cookies work, let us move to the next functionality of cookies - saving user preferences.
I will illustrate this feature using a very good example. Even if you are a new to using internet, you would have heard about the website called YouTube.com. The first time you visit YouTube.com you will see the thumbnails for a few videos. After you watch a few videos and again visit enter the URL as YouTube.com, you will notice that there will be a few links to the videos that might be of your taste.
What YouTube does is, it keeps track of the videos that you watch. This details of the videos that you watch is sent to the server via the cookies stored on your computer. When you visit YouTube’s home page, YouTube performs an analysis of the cookies and displays you links to the videos that you might be interested to watch.
You can try something similar on google.com, bing.com, etc by changing the default language. When you visit those websites again, you will see that the pages are displayed in the language that you selected to be your default choice.
Another great example iGoogle. It is probably the example that you can find on the internet. Play with them and you will understand how cookies work. Apart from saving data, customization is the next great functionality for which the cookies are used.
Image Credit: Mindmatrix - Wikipedia
Since cookies can very easily collect data about their activities and other required data, they have been adopted by almost every website to study the user’s activities and use it to their advantage. Websites like Google, collect the list of words that you search for and display advertisements according to your searches by analyzing your search activity. This is made possible by cookies that have stored all your searches.