Tag Archives: browsers

Web 101: Are Cookies Yummy?


CC Cookie image courtesy of azmichelle on flickr

Just like real life cookies, a few cookies in your browser make life fun, but too many are a bad thing. Before we can get into what’s good, what’s bad, and what you can do to manage cookies, we need to learn a bit about what cookies are.

Let’s say you have just navigated to this page. When the web server send the text that will display this page on the screen (see Web 101: Text and the Web for more on this), the web server also sends what’s called a header for the file. The header has things like a line telling your browser that the server found the file, a line saying what kind of file is being sent, a line saying how long the file is, and a few other things your browser needs to know. If the web site wants to put a cookie on your computer, it also includes the cookie in this header. For example, the header might include the line:

Set-cookie: 1127

Your browser keeps a file of cookies that it has saved, and when it sees this in the header, it adds a line of the cookie file that has the name of the website and the id number (1127 in this case) of the cookie. There will also be some other information, like when the cookie was first set, when it should expire, and the type of cookie.

The next time you visit that website (even if it’s just clicking on another page in the website), your browser will add a line to the request for the webpage. That line will be

Cookie: 1127

The web server will then look up cookie 1127 in its database, and know that you are the same person it saw before. If you have logged in to the site in the past, it will be able to match up that cookie to your account.

Because cookies are stored by your web browser, if you visit the site again on a different computer or with a different browser (say you use Firefox instead of Chrome), the site won’t recognize you and you will get a new cookie.

In the next couple of posts we’ll learn when cookies are good for you and when they are troublesome.

(Thanks to Computer Networking: A Top-Down Approach for much of the information in this post.)