Friday 4 November 2011

Cookies

Cookies
A cookie is used to return a users browser to some sort of previous state. For example remembering a user-name so the user doesn't have to retype it. Also know as HTTP cookie/browser cookie, it makes for a better user experience. Cookies are simply a string of characters no larger than 4kb. The most important variables to a cookie are max-age, path and domain. Which are self explanatory.

Why use them in our project?
For our project we intend to use "sessions", a session cookie will only last for the duration that the user is on the page. As soon as the page is closed the cookie will expire. We will also use them to remember user names and possible passwords.

How do we use them?
Creating a cookie is relatively simple process. In the html file we can use java script functions to remember the user's name. In this example http://www.echoecho.com/samplecookie1.htm the user will enter the name once and the code will remember them the next time they visit the page. The name is simple saved into a var and returned the next time they visit. We could implement this script into our project for the user name so you wouldn't have to retype it. This example also shows a function that gets rid of the cookie. This would be useful if the user was on a public computer and didn't want to share their details.