Thursday 27 December 2012

Why do goldfish need Cookies?


What are cookies and why are they required?



At the most fundamental bare-bones level, a web server is just like a goldfish with bad memory.   When you visit a web site, the underlying web server does not know and cannot keep track of each individual connection.  Say you go to a news website, each time you click on a different news story, the actual underlying server will have forgotten who you are between successive views of different web pages.  In fact, the server doesn't necessarily even know that when you visit a page with multiple photographs that it is the same computer requesting each picture for that page. 

In other words, each request for a web resource, such as a page of text, photograph or mp3 file is considered to be a totally separate connection.

One of the main reasons behind the server not keeping track of who's who based on their connection is because its impossible with situations where there might be multiple web-browsers all using a shared internet connection, such as a household that uses several laptops or an internet cafe.

Lets say a house has 3 laptops for Mummy, Daddy and son Johnny and they all enjoy logging on to the same website. Each of them has their own username and password.

The solution to this problem is through the use of Cookies. 

A cookie is a small biscuit.

In computer terms however a cookie is a mechanism for dynamic page creation technologies ( such as  PHP or ASP) that exist on top of the bare-bones web server to perform the task of creating the illusion of a continuous web "session".

When a web browser visits a web server, the web application running on the web server creates a "session key" that is sent back to the browsing computer.  On further requests to the web application, the browser sends back the "session key" - the web application is then able to determine which browser has made the request and therefore send the appropriate information.

Another example is when a login system is used like facebook or hotmail  - each laptop will receive an unique session key that identifies the particular person that has logged on.   Every time someone clicks on an email to read, the browser of that person sends the indentifying cookie back to the Web application, which is then able to know who is making the request and send the appropriate information.



These session keys are stored on the web browser computer as a cookie file.









    






No comments:

Post a Comment