Cookies: Our Misunderstood Friends
June 14, 1999
In the mortal realm, cookies have been much maligned for
their contributions to cellulite and other forms of
excess baggage. Unfortunately, these treats have fared
little better in the ether, where cookies have been tagged
as invaders of privacy and pinned with all manner of
espionage rhetoric. The truth of course is that a few cookies
now and then never hurt anyone, in either realm, and for
good reason.
Dietary debates aside, just what is a cookie on the
Web? Simply put, a cookie is a small chunk of data
that a Web site can leave on your computer, either in RAM
or on the hard drive depending on the life span of the
cookie. The data contained in this cookie is up to the Web
developer, but it usually contains some information
about your visit -- the time, or date, or some data you
entered or selected on a form. When you return to this
site in a future session, the cookie can be retrieved,
the data analyzed, and action taken as a result -- the site
may remind you when you last visited or may pre-set some
variables to match settings you chose the previous time
around.
The notion that the Web site can leave behind this dollop
of data has rubbed many folks the wrong way, which
taps into a legitimate concern: the Web should not, after
all, be a one-way mirror. Lost in the ruckus, though,
is the fact that the cookie knows nothing about "you"
or "your computer", other than that information
which is readily available or that you volunteer. Cookies
cannot see data on your machine or know your name or
address unless you have volunteered that information.
Unfortunately, a number of Web developers, motivated by ignorance
or sloth or sneakiness, instigated anti-cookie factions by
failing to reveal that supplied information was being
stored in cookies on that user's computer. The consequence
has been that a number of users are entirely anti-cookie
and choose to disable the cookie technology in their Web browsers.
Having said all of that, cookies still have a place in Web
development and, used responsibly, provide a convenient
means towards maintaining state on the web. Although
cookies could be used to maintain state both across sessions
and within a single session, we're going to look at using the
cookie to remember data between sessions. Frankly
put, there are better ways to maintain state within a session,
which we'll see later in this article.
The State of State
The Perl You Need to Know
Cookie Example: Part I -- Retrieving the Cookie
|