Assignment #3 - PHP Trivia Game
Due: start of class, Monday 2/6.
You will be creating a PHP-based trivia game.
You will be learning how to set cookies and store session data.
Overview.
The trivia game asks the user a series of multiple choice questions.
The user continues to play until all questions are answered correctly.
The web application supports multiple simultaneous users.
A unique user is a person in a different web browser.
You are free to make the game look however you like (subject to the requirement listed below).
Here is my version.
Requirements:
Your game should be started by going to trivia.php. Additional PHP pages can be used if you want.
A new user is first asked for their name. All subsequent pages greet the user by name.
Each multiple choice question should have four options.
The correct answer should be randomly assigned to one of the four positions.
The other three answers should be answers to three other questions.
None of the answers should be the same.
You should have at least 10 questions, but no more than 20.
The next question is taken randomly from the set of currently unanswered questions.
Once answered correctly, a question is never asked again.
The answer for a correctly answered question may be used as an incorrect answer for future questions.
Submitting a question with no selection counts as an incorrect answer.
Questions and answers should be loaded from a flat text file trivia.txt.
Draw your questions and answers from wherever you like, for example here are some computer science trivia questions.
The questions should be sensible enough to give me some chance of winning without exhaustive search.
A user's game session should live for up to an hour (e.g. they can exit their browser and start it back up within an hour an continue the same game).
The cookie set by PHP should be marked HttpOnly, we don't want any cross-site scripting attacks on our poor trivia game!
After submitting a question, the page should display a message indicating if the answer was correct or not.
After submitting a question, the page should display the number answered correct, the total number of questions, and the total number of guesses.
Once all questions are answered correctly, display a congratulation screen. Bonus points for a fancy page.
Once all questions are answered correctly, tear-down the PHP session and expire the user's cookie. This means if the user returns to the page from the same browser, the game starts over (including asking for their name).
Your code should feature descriptive variable names and comments describing at a high-level what different sections do.
Submission.
I will be testing your application by logging into your sever, starting Apache and then going to your trivia.php page.
Submit your PHP file(s) and trivia.txt to the Moodle dropbox.
The Moodle timestamp is the completion time for the assignment.