What is a Cookie?
Cookies are small files which are stored on a user's computer.
They are designed to hold a small amount of data specific to a particular
client and website, and that can be accessed by the web server and the client browser.
Why cookies are necessary?
Even before jumping into
the details of cookies, let’s see why cookies are required and why has it
become an essential piece in the web world.
1. Provides
information about the user
a. How many users are visiting the
website?
b. How many of them are new?
c. how often does the users visit?
2. User
Preferences
a. User customization will be stored so
that the same preferences will be restored when the same user logins again.
3. Tracks
the session
a. When online shopping, database adds
the shopping carts based on the items we choose. By the end, it will be able to
tell how many items did the user select. Database saves the shopped carts
tagged with unique id generated by Cookie.
Cookies are a convenient way to carry
information from one session on a website to another, or between sessions on
related websites, without having to burden a server machine with massive
amounts of data storage. Storing the data on the server without using cookies
would also be problematic because it would be difficult to retrieve a
particular user's information without requiring a login on each visit to the
website.
If there is a large amount of information
to store, then a cookie can simply be used as a means to identify a given user
so that further related information can be looked up on a server-side database.
For example the first time a user visits a site they may choose a username
which is stored in the cookie, and then provide data such as password, name,
address, preferred font size, page layout, etc. - this information would all be
stored on the database using the username as a key. Subsequently when the site
is revisited the server will read the cookie to find the username, and then
retrieve all the user's information from the database without it having to be
re-entered.
What's in a Cookie?
Each text file has name
value pairs and information about the website. So each website has
got its own Cookie
files. So your cookie file looks something like this:
UserID A9A3BECE0563982D www.goto.com/
Website has unique
ID given by the web server for each user.
When are Cookies created?
Writing data to a cookie is usually done
when a new webpage is loaded - for example after a 'submit' button is pressed
the data handling page would be responsible for storing the values in a cookie.
If the user has elected to disable cookies then the write operation will fail,
and subsequent sites which rely on the cookie will either have to take a
default action, or prompt the user to re-enter the information that would have
been stored in the cookie.
How it works?
When you click “www.
Amazon.com” in browser, it will look into your hard disk and searches for
cookie file. If it finds, Cookies will send that name-value pair information to Webserver along with URL. If it doesn’t find, it will not send cookie data. So webserver
will understand that you are a new user and allocate a unique id that will send
in the subsequent response. Browser will place this cookie information in hard
disk.
The time of expiry of a cookie can be set
when the cookie is created. By default the cookie is destroyed when the current
browser window is closed, but it can be made to persist for an arbitrary length
of time after that.
Types of Cookies
1. Session Cookies/Transient Cookies
These cookies get erased when you close the Web browser. The session cookie is stored in temporary memory and is not retained after the browser is closed. Session cookies do not collect information from your computer. They typically will store information in the form of a session identification that does not personally identify the user.
2. Persistent Cookies
This is also called as permanent cookie/stored cookie. This cookies are stored on your hard drive until it expires (persistent cookies are set with expiration dates) or until you delete the cookie. Persistent cookies are used to collect identifying information about the user, such as Web surfing behavior or user preferences for a specific Web site.
These cookies get erased when you close the Web browser. The session cookie is stored in temporary memory and is not retained after the browser is closed. Session cookies do not collect information from your computer. They typically will store information in the form of a session identification that does not personally identify the user.
2. Persistent Cookies
This is also called as permanent cookie/stored cookie. This cookies are stored on your hard drive until it expires (persistent cookies are set with expiration dates) or until you delete the cookie. Persistent cookies are used to collect identifying information about the user, such as Web surfing behavior or user preferences for a specific Web site.
No comments:
Post a Comment