SYST28043 - 3 UNITS
WEB TECHNOLOGIES


COOKIES JAVASCRIPT SAMPLE

Cookies let you store information on the client's computer and read it again when they leave the page and come back or even when coming back after closing the browser. Often you store an id and then you can look up that id in a database to present the user with relevant information or track them. You can store data right in the cookie too. Here we store the user's name and welcome them back. Below are some points about cookies:

  • you can set the expiry date of a cookie
  • if you do not set a date then it expires when the user closes all browser windows
  • if you set a date in the past it deletes the cookie
  • a Web site can only read cookies that they set
  • there are various options as to setting cookies for various subdomains

Try it out by submitting your name - then leave the page and come back:



Name:



In the text box below is the code less the script tags. Note that there may be multiple cookies stored. So to get the cookies you have to split the cookie string to get the right variable back. The string looks like this: variable1=value1; variable2=value2; etc.


Sheridan - School of Applied Computing and Engineering Sciences - Web Technologies