Out: Mar 28, 2017
Due: Apr 18, start of class

CENG256LAB 6

For steps 2-5 use JQuery to make any and all changes the web page.

  1. In your form for submitting questions for Lab 5, show how the form is vulnerable to an HTML injection attack. Create a second version of the code that is safe from such an attack. (4 marks)
  2. Modify your code for inserting values into the Questions table so that it uses prepared statements rather than raw insert. (3 marks)
  3. Rewrite survey.php as survey2.php. Instead of generating the HTML on the client, pass the questions and answers as JSON encoded data, generated from the original plain text file.

The generated code should look something like this: (3 marks)
var quiz={ test :
{ question: ‘This is a question’, answers: [‘Answer 1’, ‘Answer 2’], correct: ‘Answer1’},
…. Additional questions….
}

  1. In survey2.php include a JavaScript script that generates the multiple choice questions as from the above HTML. The output should look approximately the same as the output in Lab 4. But with the following differences: (4 marks)
  2. Enclose the question itself in a <DIV name=qname> </DIV> tag. You should be able to reference the text of the question using the selector DIV[name=qname]at a later time.
  3. Next to each question put 2 buttons labelled “Local Check” and “Remote Check”. When you click the first button call a function localCheck(qname) and a function remoteCheck(qname). You’ll be adding the code for this step 6.
  4. Add a JavaScript function
  5. Implement localCheck. Compare the selected answer to the correct answer in the JSON object. It they match turn the colour of the question to green. If they do not, change the colour to red. (2 marks)
  6. AJAX
  7. Add a button to the web page with an Ajax styled function to put the current time on the server at the top of your quiz. This is simply a practice question using AJAX. (2 marks)
  8. Implement remoteCheck. Use AJAX to submit the text of the selected answer and an identifier indicating the question number to the server. If the answer is correct have the server return “Good”. If wrong have it return “Bad”. You should write the answer to the console to verify that it is working. If the answer is wrong, hilite the question by decorating it using STRIKETHRU and change the colour to orange. If it is correct italicize the text and change the colour to cyan. (4 marks)
  1. JSP
  2. Copy the form used in Lab 3 to Lab6Form.html. Attach it to a JSP page and have that program individually report on the values in the fields. (2)
  3. Check if there is a session variable LASTARRIVAL. If no such session variable exists create one and display a message: “Welcome 1st time user” along with the user’s ip address. Save the time and date in a session variable LASTARRIVAL.
    If there is already such as session variable, display a message “Welcome back “ along with their IP address. Display the time and date of when they last arrived, then update LASTARRIVAL. (3).
  4. Modify the value stored in LASTARRIVAL so that it is an ArrayList (or other extendable storage object). Store and display all of the users arrival times. (2 marks)

There are 28 available marks. A status report is required for each of the above questions as are program listings. This assignment will be marked out of 25. Describe and add any additional bonus features up to a total of 8 marks.