A cookie is a small piece of text stored on the visitor's computer by a web browser. As the information is stored on the hard drive it can be accessed later, even after the computer is turned off.
A cookie can be used for authenticating, session tracking, remember specific information about user like his name, password, last visited date etc.
You can set a cookie setting document.cookie to a cookie string. Later we will discuss details how to create and retrieve a cookie.
Example of cookies
Here is an simple example where have set a cookie with the UserName as George, and an expiration date of Mon, 14 July 2011.
What cookies cannot do ?
- The first is that all modern browser support cookies, but user can disable them. In IE, go to Tools and select Internet options, a window will come. Click on privacy and select advanced button, another new window will come, from here you can disable cookie.
- Cookies can identify the computer being used, not the individual.
- Most modern browser is expected to be able to store at least 300 cookies of four kilobytes (4 kb) per server or domain.
- For each domain and path you can store upto 20 cookies.
- Cookies cannot accessed by any other computer except the visitor's computer that created cookie.
- A website can set and read only its own cookies (for example, Yahoo can’t read IE's cookies).