This is a team project. Students are encouraged to work in pairs. Individual teams and teams of size 3 are by permission only. Please contact the instructor for permission.
You will use one of the FTP accounts that we have been using in lab to upload/submit. You do not need to submit this project via Blackboard.
index.html
file into
the root folder of the primary account you selected, so that the folder
listing will not be displayed.project4
,
Project4
, Project 4
, etc.
Do not use spaces in your folder name.
Note that folder names are case sensitive, so
secret
and Secret
are different folders. Don't use either of those names. Use only letters and numbers
in your file name.
drlimrules
,
(don't pick that name),
and your FTP username is s987654, then
your project URL ishttp://s987654.sienasellbacks.com/drlimrules
Project 4 URL
http://s987654.sienasellbacks.com/drlimrules
,
your email should simply contain the following content:My team partner is Ash Ketchum and our URL is http://s987654.sienasellbacks.com/drlimrules
My team partner is Tracey Sketchit and our URL is http://s987654.sienasellbacks.com/drlimrules
Note that the setup task above is worth 5 points.
Your application will store data in two tables Users
and Questions
as well as a file called rankings.txt
.
Because we are working in a shared environment,
your table names need to be unique. I recommend naming them
Users??????????
and Questions??????????
where ??????????
is
a difficult to guess sequence of characters and/or numbers.
While you will want to create new tables, the tables are identical to the ones we created in labs 7 and 8.
To be specific, here are the SQL statements to generate the tables:
CREATE TABLE Users?????????? ( username VARCHAR(64) NOT NULL, password VARCHAR(64) NULL, usertype VARCHAR(64) NOT NULL DEFAULT 'normal', games INT NOT NULL DEFAULT '0', points FLOAT NOT NULL DEFAULT '0.0', PRIMARY KEY (username) )
games
are the number of times the user plays trivia.
points
are the total number of points they earned.
Here I'm using a float just in case we want questions to be worth fractional points.
But, one "trivia game" will present 10 random questions where correctly answering a question
earns 1 point.
CREATE TABLE Questions?????????? ( id INT NOT NULL AUTO_INCREMENT, question VARCHAR(1024) NOT NULL, choice1 VARCHAR(1024) NOT NULL, choice2 VARCHAR(1024) NOT NULL, choice3 VARCHAR(1024) NOT NULL, choice4 VARCHAR(1024) NOT NULL, answer INT NOT NULL, PRIMARY KEY (`id`) )
Implement a web application that allows any user to...
After logging in, the user is displayed with a menu of links to do the following. [5 points]
$_SESSION['username']
.
[15 points]
rankings.txt
,
just like we did in project 3.
Use the question id
to identify the specific questions.
If a user likes question 7
better than question 3
,
the string 7>3,
will be appended to file.
[10 points]
session_destroy()
and unset the SESSION
variable on the server.
Remember that you have to start/restore a session to destroy a session.
[5 points]
Back Links / Redirection
After a user adds a question, plays a game of trivia, views the leader board
or ranks questions, you must
either have back links to the menu of options
or you should redirect the browser back
to the main menu page. Below is the code to do
a redirect to a script called home.php
assuming your FTP is s987654 and you secret folder is drlimrules.
[5 points]
header("Location: http://s987654.sienasellbacks.com/drlimrules/home.php");
Secure Your Scripts:
In development, it is OK if your scripts are publicly accessible.
But, you must eventually secure all your scripts.
The functionality above should only work if the user logs in.
Remember that you can set a session variable at login
and then check it at the top of each secured script.
You should use the die
function to terminate scripts
so they do not produce output.
[5 points]
session_start(); if ($_SESSION['authenticated'] != true) { die("Access denied"); }
$hashOfABC = password_hash("abc", PASSWORD_BCRYPT);
$sql = "INSERT INTO Users?????????? VALUES ('alice', '".$hashOfABC."', 'admin', '0', '0')";
[5 points]
admin
.
The login query can also fetch the usertype
:$result = $mysqli->query("SELECT password, usertype FROM ????? WHERE username='$usr'"); $row = $result->fetch_row(); $stored_password = $row[0]; $user_type = $row[1];A session variable can be used to store the usertype, i.e.,
$_SESSION['usertype'] = $user_type
.
If $_SESSION['usertype'] == "admin" you can generate additional menu items
to the following admin-only scripts.
[points 5]
Note that it is possible to earn 85 points without implementing the question ranking functionality, which is most challenging, and the additional features. AJAX can be difficult to debug. Adding Bootstrap can be very time consuming, so save these for the end. You can only earn a maximum of 100 points, but you could lose points for errors, so attempt more then 100 points. Do not waste time making your application look "pretty." Appearance is not a part of the grading criteria at all.
The admin functionality to display and delete users and questions is very useful. You should actually implement items #8, #9, #10 and #11 first.
Script for creating, showing and deleting users should already be complete (see lab 7). But, instead of creating a drop-down menu for deleting users, we can add delete buttons to the show user script. Thus, we know the details of the user we wish to delete. In lab 9, we will do this as an activity to help you get moving.
Script for creating and showing questions should also be complete (see lab 8). You just have to add delete functionality similar to deleting users.
You already implemented a login script (see lab 7). But, you have to add functionality to fetch the user type so the main menu or homepage can be customized for admin users.
The main menu or homepage is just a basic web page with links to the other scripts. All you have to do is session protect this page, which means it needs to be a .php file, so you can add PHP code.
In lecture and lab 10, we will revisit the item ranking script, which you can customize to rank your questions. Ranking questions is the same as ranking items/ponies (see Project 3). But, instead of selecting items from a hard-coded JavaScript array, you must write a script to randomly fetch two questions from the database that is constantly changing. Note that playing trivia does exactly the same thing, but only selects one question. A key difference, is that you simply have to display the question and choices, whereas playing trivia requires generating a form that works.
Be sure to upload your working application to the URL you specified in the initial task.
You should not share your code with anyone but your project partner. This is an open-ended creative project. Excessive similarity will be considered plagarism.