IT350: Web & Internet Programming

Lab 8: Cookies


We have now learned about cookies, and more about Perl. In this lab you will practice those skills and you will install Perl on your Bancroft computer.

Lab Requirements

You must create a folder on your Web drive called "Lab08" (without the quotes) and store your work in that directory.

Download cookie_js.html from here (right-click and "Save link as...") and store it in your Lab08 directory.

1. JavaScript - Add cookies:

Modify cookie_js.html such that:

  1. Your page stores two distinct pieces of information using two cookies (e.g., user's name and favorite color)

  2. Your page uses the two pieces of information stored in cookies to display some personalized (style and/or content) content. The user should not be required to enter any information if the cookies are present.

  3. The page does something reasonable when no cookie is stored (the first time the page loads) – be sure to check this at the end!

  4. Both pieces of information can be changed by the user at any time without reloading the page, and the new information is stored in cookies. For instance, you might use text boxes or buttons to let the user reset the cookie values (e.g., change their favorite color).

  5. All of the functionality described above should be obvious to the user: what cookies are stored, how the information stored changes the page, and how the user can change what is stored.

Example: you store the user’s name and favorite color. When the page loads, the page displays their name and changes the background to their favorite color. The users can change the values stored in the cookie by clicking on buttons, causing a pop-up box to prompt them for the new information. (you do NOT have to do this specific example, but you must follow the listed requirements)

Hint: Use the functions provided in the starter code to create, read, and delete cookies.

2. Perl: Fraud Check

Next you will create a perl script that simply checks for the presence of valid cookies. The script should read one of the cookies you created with JavaScript and check that value against a list of fraudulent values stored in a file on the web server called "fraud-values.txt". Create a sample file "fraud_values.txt" that includes at least three different values (but your script should work for any number of values in the file). You pick which of the 2 distinct pieces of information stored in the cookies gets checked. Modify your script so that:

  1. If a cookie is not present, the message "No cookie present" is displayed to the user in the browser
  2. If a cookie is present, and your script finds a "fraud match" (the value was found in the fraud_values.txt file), the program should display to the user "The value XXX indicates a fraud!!", where XXX is replaced by the cookie value.
  3. If a cookie is present, but your script finds no "fraud match" (the value was NOT found in the fraud_values.txt file), the program should display to the user "The value XXX does not indicate a fraud. Congratulations!" where XXX is replaced by the cookie value.
  4. Your program should work for any number of values in fraud_values.txt, not just on the sample file you created.

Test your program by fetching the URL

3. default.html

  1. Add a link to Lab08/cookie_js.html to your default.html page
  2. Add a link to Lab08/ to your default.html page
  3. On your coversheet, explain to the instructor what cookie value is detected as being a fraud match and what cookie value is not a fraud match.

4. Install Perl on your Bancroft computer:

  1. If you do not have Perl installed on your computer, download and install Perl from (free community edition)
  2. Make a test file and save it on your C drive. This file should have the following, where you replace XXXXXX with your name:

    use Sys::Hostname;
    print "Perl runs on XXXXXX's computer -- woo-hoo!\n\n";
    print hostname() . ":" . localtime() . "\n";
  3. Open a command prompt: To do this on Windows XP, click on the "Start" button at the lower left corner of your screen, pick "Run", then type "cmd" and hit return. On Windows Vista or Windows 7 Professional, click on "Start" button at the lower left corner of your screen, then type "cmd" in the "Search" box, and hit return.

  4. Go the directory where is (cd C:\ if you saved it directly on your C drive)
  5. run: perl
  6. If you get an error because "perl" is not recognized as a command, you need to specify the entire path to perl. For example, if you installed perl in the perl directory on your C drive, you might need to type at the command prompt: C:\perl\bin\perl
  7. Take a screenshot of the output. On Windows: Use Alt-PrintScreen to take a screenshot, then paste it somewhere (like in Word). On Linux:you probably know what to do already. If you must, you can just paste the text and print that.
  8. Print out the screenshot and turn it in with your lab.

Your web page must be constructed using Notepad++ or a similar text-only editor. The use of programs such as Microsoft Word, Microsoft Frontpage, DreamWeaver, ColdFusion, Mozilla Composer, etc. will be considered an honor offense.


  1. Your web page with JS cookies should be called "cookie_js.html" (without the quotes).
  2. Your perl script should be called "" (without the quotes).
  3. Your pages should contain all of the elements described in the requirements section above.
  4. All of your files should be in a folder called "Lab08" (without the quotes) on the Web drive. Your instructor will assume that your web pages are viewable at and where XXXXXX is your alpha number. You may want to check that these URLs are viewable and that everything works correctly from a computer where somebody else is logged in. If you've goofed and linked to a file on your X drive, this will help you catch it!
  5. Turn in the following hardcopy at the beginning of class on the due date, stapled together in the following order (coversheet on top):

    1. A completed assignment coversheet. Your comments will help us improve the course.
    2. On your coversheet, give an example of cookie name and value that is detected as being a fraud match and a cookie value that is not a fraud match.
    3. A printout of the source to your file (not the rendered page you see in your browser).
    4. The printscreen of your perltest run from the command line on your Bancroft computer
  6. Make sure you have the required links on your default.html page!! (see above)