1. Home
  2. Computing & Technology
  3. Web Design / HTML

Build Your First HTTP Cookie
It's Easy to Use Cookies On Your Web Site

By , About.com Guide

In my article on HTTP cookies, I explained how HTTP Cookies work and how they can affect you. Let me reiterate that HTTP Cookies are only as dangerous or invasive as you allow them to be. If you fill out a form with your name, address, and phone number, that information can be stored in an HTTP cookie on your machine. However, the cookie cannot grab that information from your machine or otherwise know anything about you other than what any HTML coder can know.

I would like to give you a general answer about cookies and advertisements, which is how About.com uses some of their cookies. One way other companies use cookies is to try to display a variety of ads. If you have seen an ad for a new computer 3 times and haven't clicked on it, chances are a 4th time won't do the trick. Using a cookie can track how many times you've seen a particular ad and gauge it's success rate.

Cookies can also be used to gather demographics about a computer user. The advertising company doesn't know who you are or where you live or anything like that, but every time you accept a cookie from them, you tell them a little bit about where your computer has surfed that day. So, if you frequent running Web pages and natural food store pages, they can use that information to target banner ads to your computer. Of course, if you sell the computer with the harddrive intact, then they will have incorrect information. Also, if more than one person uses the computer the information won't be very accurate. And finally, if you delete your cookies.txt file every once in a while or don't accept cookies from external servers the information cannot be gathered. (Most ad servers are a separate company and so if you accept cookies from the server you are on you will still be able to use e-commerce on the site without getting demographic data about your surfing habits out to advertising houses.)

How Can I Set a Cookie?

Cookies are set by the browser, often with a CGI or JavaScript. You can write a script to set a cookie at any event on a Web page. For example, if you go to this page you will be given the option to set a cookie when you click another link. The cookie looks like this:

Set-Cookie: Count=1; expires=Wednesday, 09-Nov-1999 23:23:40 GMT; path=/; domain=webdesign.about.com

And what it means is:

  • Count=1
    This is the name of your cookie.
  • expires=Wednesday, 09-Nov-1999 23:23:40 GMT;
    This details when the cookie will expire.
  • path=/;
    This is the minimum path that needs to exist for the cookie to be returned.
  • webdesign.about.com
    The domain that set the cookie, and is the only domain that can retrieve the cookie.
You can use cookies to store information from forms, so that every time someone returns to your page, you can display their name, or what they prefer on their intro page, and so on. The other really common use of cookies is with e-commerce as a shopping cart.
Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

©2009 About.com, a part of The New York Times Company.

All rights reserved.