IT350 - Web and Internet Programming

Lab 09 – Cookies, Perl and files

Introduction

Last week we have learned about cookies and more about Perl. In this lab you will return to your site and add both of these features.

Lab Requirements

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

 

1.     Download cookie_js.html from the course webpage and store it in your Lab09 directory. Right-click on cookie_perl.txt and then save it in W:\Lab09\cookie_perl.pl (you must change “Save as type” to “All files”.  Then change filename from cookie_perl.txt to cookie_perl.pl)

 

 

2.     Java Script - Add cookies: Modify the cookie_js.html page such that:

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

b.     Each piece of information influences the style or content of your page

c.      Both pieces of information can be changed by the user, and the new information is stored in a cookie

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

 

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.

 

3.     Perl - Fraud check: Next you will modify your perl script to use cookies. The cookie_perl.pl 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. You pick which of the 2 distinct pieces of information stored in the cookies gets checked. Modify your cookie_perl.pl script so that

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

b.     If a cookie is present, and your script finds a “fraud match” (the value was found in the fraud_values 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 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.

 

Test your program by fetching the URL http://intranet.cs.usna.edu/~mXXXXXX/Lab09/cookie_perl.pl

4.     Links:

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

b.     add a link to Lab09/cookie_perl.pl to your default.htm page

 

5.     Instructions (IMPORTANT): on your default.htm page, explain to the instructor how to see that your site does what it should.  In particular, give answers to these questions (and number your answers):

a.      What two pieces of information are stored via a cookie (and how does it affect the display)

b.     How does the user change what is stored?

c.      What does your cookie_js.html webpage do if no cookie is present?

d.     What cookie value is detected by cookie_perl.pl as being a fraud match?

e.      What cookie value is detected by cookie_perl.pl as NOT being a fraud match?

 

 

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.

Deliverables

  1. Your main web page should be called "cookie_js.html" (without the quotes).
  2. Your perl script should be called "cookie_perl.pl" (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 "Lab09" (without the quotes) on the Web drive. Your instructor will assume that your web pages are viewable at http://intranet.cs.usna.edu/~mXXXXXX/Lab09/cookie_js.html and http://intranet.cs.usna.edu/~mXXXXXX/Lab09/cookie_perl.pl  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. A printout of the source to your cookie_js.html file (not the rendered page that you normally see with Internet Explorer).
    3. A printout of the source to your cookie_perl.pl file (not the rendered page that you normally see with Internet Explorer).
  6. Make sure you have the required links and instructions on your default.htm page!! (see above)