CSc 337 - Web Programming > Assignments > Assignment 10

General Information

Due: 27 Feb 2012, 11:59pm

Abstract

In this assignment, you will be adding a simple user system to the ongoing chat project and, instead of storing data in a file, storing data in MySQL. To save time, you should continue to use your chat system from Assignment 8 with your database from Assignment 9. If you were not able to finish either assignment or would prefer to not use your solution, you may use the Instructor Solutions for both assignments.

Assignment

The following changes should be made to your solution from Assignment 8:

  1. Rename alone.php to chat.php and alonesave.php to savemessage.php. Update your form and redirect as necessary.
  2. Your application should have four new files, with functionality described below:
    1. newuser.php: contains a form to create a new account, with a username and password field. The form should submit to adduser.php.
    2. adduser.php: when submitted to from newuser.php, this script should create an account by INSERTing into the database.
    3. login.php: should show a login form with a username and password and should have a link to newuser.php in case the user does not have an account. The login form should submit to processlogin.php.
    4. processlogin.php: should look up the user in the database and, if they provided valid login information, redirect them to chat.php; otherwise, redirect them back to login.php.
  3. Maintaining logins should be handled with PHP's sessions. If a user is not logged in, they should not be able to view the chat room at chat.php and they should not be able to submit chat messages to savemessage.php.
  4. Instead of storing data in files, data should now be stored in your MySQL database, using your users and messages tables from Assignment 9.
  5. The chat history box should show who sent each message along with when it was sent and the message itself.
Hints

Examples of PHP's session functionality can be seen in the PHP class examples, inside the session_*.php files.

Examples of calling MySQL from PHP can be found in the MySQL class examples.

When determining the current date to store in the database, MySQL can set the current time with the value CURRENT_TIMESTAMP in your INSERT query.

To connect to the MySQL database, make sure your PHP files are on the class web server and use this connection string:

$db = new PDO("mysql:host=localhost;dbname=your_db_name");

Notes

You are required to use PHP's PDO functionality for MySQL, not the older (and deprecated) mysql_ functions.

Homework Submission

As detailed on the homework submission page, this homework must be on the class web server in a folder titled homework10 for it to be graded.