For those new to web development and 'how things work', cookies can be a very confusing matter. In this tutorial, Timothy gives you an overview of cookies to help you understand how they work.
A cookie is a small bit of information stored on a viewer's computer by his or her web browser by request from a web page. The information is constantly passed in HTTP headers between the browser and web server; the browser sends the current cookie as part of its request to the server and the server sends updates to the data back to the user as part of its response.
The size of a cookie depends on the browser but in general should not exceed 1K (1,024 bytes). The information can really be anything... it can be a name, the number of visits to the site, web based shopping cart information, personal viewing preferences or anything else that can be used to help provide customized content to the user.
In addition to the information it stores, each cookie has a set of attributes: an expiration date, a valid domain, a valid domain path and an optional security flag. These attributes help ensure the browser sends the correct cookie when a request is made to a server.