19 April 2009

Cookie

A cookie is used to store small piece of information on 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 request coming from the same or different client.You can use cookies to keep track of individual user who access a web page across HTTP connection.

There are two types of browser cookies - session and persistent.

First one is Persistent cookies and Second one is Non-persistent cookies.

Persistent cookies :-
Persistent cookies are stored on your computer HardDisk. They stay on your hard Disk and can be accessed by web servers until they are deleted (or)Have Expired. Persistent cookies are not Affected by your browser Setting that delete temporary files when you close your browser.


Non-persistent(or session) cookies:-
Non-persistent cookies are saved only while your web browser is running. They can be used by web server only until you close your browser. They are not saved on your disk.

Single valued cookies and multivalued cookies.
Single valued cookies we can store only one value. In multivalues cookies we can store multiple values.

We cannot write cookie when the cookies can be disbaled in client machine. A cookie can store only up to 4 KB of information. Generally cookies are used to store data which user types frequently such as user id and password to login to a site. You would want to store a user number or other identifier. Then, when the user visits your site again, you would use the user ID to look up user details in a database. We can also say that cookies are the Electronic ID tags sent from a Web server to a user's browser to track and record their Web-surfing patterns, i.e., ads clicked on, products purchased, sites visited and the user's origin. This can enable the site to provide more personalized information to be served upon a return visit to the site.

No comments: