A cookie is used to store a small piece of information on a client machine. A cookie contains page-specific information that a Web server sends to a client along with page output. Cookies are used for sending page-specific information because HTTP is a stateless protocol and cannot indicate whether page requests are coming from the same or different clients.
Cookies provide another way that you can store information for later use. Cookies are small files that are created on the client’s hard drive. One advantage of cookies is that they work transparently without the user being aware that information needs to be stored.
Cookies also can easily whether any page in your applications and even be retained between visits, which allows for truly login term storage. Some of the drawbacks that query strings, cookies stored limited to simple string information and easily accessible and readable if the user finds and opens the corresponding files.
Some user disables cookies on their browsers, which will cause problems for the web application that require them. Alos users might manually delete the cookie files stored on their hard drives but for that most part, cookies are widely adopted and used extensively on many Websites.
Cookies can either be Temporary or Persistent.
Temporary cookies also known as session cookies, exist in the memory space of browse. When the browser is closed all session cookies added to browse are lost.
A Persistent cookie is saved as a text file in the file system of the client computer.
Advantages of using Cookies:
- A cookie is stored on the client computer and can be read by the server after a request for a page is posted. Therefore, no server resource is invoiced in maintaining the cookie.
- A cookie is a text-based data structure that contains key-value pairs. It is easy to create and manipulate cookies.
- A cookie can either expire when the browser session ends or exits indefinitely on the client computer.
Limitations of Using Cookies:
- Cookies that are stored on client computers have a limited size. The most browser allows cookies to have up to 4096 bytes in size. You cannot store a large amount of data in the cookie.
- User can disable cookies