Cookies are the small pieces of data stored on the computer's browser directory or in the program data subfolders. Cookies are created when a Website is first visited by the user and then track the user’s behavior within the site. They are used to maintain state information as the user visits different pages on a Web site or return to the Web site at a later time.
Cookies usually do not contain much information or doesn’t need hard coding. It mainly contains the URL of the website the user visited or that created the cookie, the duration of the cookie's abilities and effects, and a random number.
Types of Cookies
There are two types of cookies that are as listed below:
These cookies are temporary cookies and are stored in the computer's memory only during a user's browsing session and are automatically deleted from the user's computer when the browser is closed. They are widely used by commercial web sites, for example, to keep track of items a consumer has added to their shopping cart.
Persistent or Permanent or Stored Cookies:
These cookies are stored on the user's computer permanently and are not deleted when the browser is closed. They can retain the user preferences for a particular web site and allow those preferences to be used in future browsing sessions. Permanent cookies are usually configured to keep track of users for a prolonged period of time.
How Cookies work?
When the user visits a site that uses cookie for the first time, a cookie is downloaded onto the PC. The next time when the user visits that site, PC’s browser checks to see if it has a cookie containing that site name and sends the information contained in that cookie back to the site. Then the site stores a corresponding file with same ID tag to the one they set in your browser and in this file they can track and keep information on the user’s movements within the site.
A website can even “tag” the computer with a cookie, which identifies that user as a unique visitor to that site. Later when user visits the site again, the Web site can read the value of this cookie that's stored on that computer to identify the user.
Purpose of Cookies