Cookie is a piece of information stored in client machine and used to transport information from server to client and back as an HTTP header in script.

TYPE OF COOKIES

Learn more about type of cookies.

WHY USES COOKIES

HTTP protocol works as stateless protocol. When the web server completes client request, there is no connection between the web server and client. Cookies mainly used to store web state and visitor behavior in the local machine. It is useful to track user activity on website such as no of visits and last user visit on the website. These information later can be used to analyze user behavior. Cookies are purely client based and stored in client machine. It send to the web server when request made. Some of the example are:

User Preference Setting
Cookies are used to store user preference information. When next time user request the same page, script force browser to check user preference in cookies and deliver html page based on the value set in cookies. In this way, user will be able to see customize page without setting up preference each time they visit the page.

Shopping Cart Tracking
Cookies are also used to store shoppers activity track on website while shopping. When user visit shopping site, a user cookie will be set with shopping id number. Each time you select an item to purchase, that item is added to shopping cart. On the check out page each item will be listed associated with your shopping id number. Without cookies, you are require to keep track of each item you want to buy and type them into checkout page or buy item one by one.

PROS & CONS

I am listing down each pros and cons here:

  1. All client do not support or accept cookies. If client accept cookies, cookies can be disabled manually by user preference.
  2. Server has no control over the age of cookies. It might be destroy before the time by several reason. Some of them are;
    • Browser reaches its maximum capacity and has no more room to store new cookies. Cookies expiration time depends on client clock that can not be accurate always.
    • Each cookies must be less then 4kb.
    • Only 20 cookies allows per domain
    • Not more then 300 cookies can be stored in client machine.
  3. Using cookies, websites can keep track of user behavior such as navigation, type of website they visit, type of advertisement banner the click on, type of shopping item they purchase, keyword used to make searches in search engine. All these information can be collected and could sell these information to marketing agency or other black or white companies.

Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.