spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / cookies 123456

JavaScript Cookies:

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Making the Most from the Drudgery of Others

How they work

When you click on a link or otherwise access a URL, your browser sends a request for the file in an HTTP header (that you don't see) to the server that looks something like this:

Content-type: text/html

This lets the server know what type of document that is being requested by the browser. If this is your first visit, or have no cookie yet, the HTTP header request contains no cookie information. Then, the server sends back an HTTP response header to you instructing the browser to create a cookie file on your hard drive (if there is a script to put one there). That looks something like this:

Content-type: text/html
Set-Cookie: name_of_cookie=Value_of_cookie; path=/;
expires Mon, 09-Dec-2002 13:46:00 GMT

If you have a cookie for that site or URL already, the cookie info is sent along with the HTTP header request initially, then the server knows you have a cookie for that URL. Then the cookie info is used by a CGI program, or JavaScript.

In Summary, it's this simple:

You don't have a cookie yet
You have a cookie already
1. You click on link 1. You click on link
2. HTTP Header request is sent to server and has no cookie info. 2. HTTP Header request is sent to server and has cookie info.
3. Server sends back HTTP response and says "Put a cookie on the hard drive!". 3. Server/script reads cookie and the data is processed.
4. You now have a cookie.  

Cookies store data in name and value pairs. The name and value can be composed of whatever you wish. An example would be MyCar=Junker. The complete list of cookie parameters that can be used to specify a cookie are (Ladd & O'Donnell, 1999) :

name=value;
expires=date;
path=path;
domain=domainname;
secure

A JavaScript that you write or use can utilize whatever name/value pairs that you want to accomplish your task.

To Continue, Use The Arrow Buttons 123456

http://www.internet.com

Comments are welcome
Produced by Greg Meckes

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: Jan. 12, 2000
Revised: Jan. 12, 2000

URL: http://webreference.com/programming/javascript/cookies/