IT350 - Web and Internet Programming

Lab 08 – Cookies: JavaScript and Perl


Last week we have 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.     Java Script - Add cookies: Modify the cookie_js.html such that:

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

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

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

d.     Both pieces of information can be changed by the user, and the new information is stored in cookies

e.      All of the functionality described above should be obvious to the user: what cookies are stored, how the information stored changes the page, how can the user 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 the same thing as the above 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 uses cookies. The script should read one of the cookies you created with Java Script 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

a.      If a cookie is not present, the message “No cookie present” is displayed to the user in the browser

b.     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.

c.      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.

d.     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.htm:

a.      add a link to Lab08/cookie_js.html to your default.htm page

b.     add a link to Lab08/ to your default.htm page

c.      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:

a.      If you do not have Perl installed on your computer, download and install Perl from  (free community edition)

b.     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";


c.      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.

d.     Go the directory where is (cd C:\ if you saved it directly on your C drive)  

e.      run:



f.      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:



g.     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.


h.     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 cookie_js.html file (not the rendered page that you normally see with Chrome).
    4. A printout of the source to your file (not the rendered page that you normally see with Chrome).
    5. 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.htm page!! (see above)