JavaScript : Smart Sites and Cute Cookies
Dr Benton
Reading/Writing Cookies
We have already said that a cookie is a little text file. This means that the data are written as pure text. We will use a
specific character to separate the various data stored in the cookie.
Why a separating character? Imagine the following cookie content:
Wally1110081999
So how do we go back and find Wally's age (1, 11 or 111 years old?) and the date of his last visit? Now note the difference
with a data separator:
Wally!11!10!08!1999
Wally is
11 years old and the last time he visited your site was on 10 August 1999.
Now we have the rudiments of cookie writing. But before we can write data into a cookie, we have to create it. There's no
big mystery to this - JavaScript will be our only tool.