CSc 337 - Web Programming > Assignments > Assignment 8

General Information

Due: 17 Feb 2012, 11:59pm

Abstract

In this assignment, you will be augmenting the "forever alone" chat (Assignment 6) to save chat history, among other functionality. If you were not able to finish the prior assignment or would prefer to not use your solution, you may use the Instructor Solution for Assignment 6 as a code base.

Assignment

Starting from the original forever alone chat, create an additional PHP file called alonesave.php that will process POST data sent to it by your chat form. You should rename the alone.html file to alone.php.

The sequence of events when a user views your site is as follows:

  1. A client requests alone.php, which returns a page populated with chat history from a stored file alonehistory.txt.
  2. Given a page that the user sees at alone.php (whether it's the first time with no messages yet or otherwise), they should be able to use the form on the page to send a message via POST to alonesave.php. This file will process the incoming POST data by:
    1. Pre-pending the incoming message string with a formatted timestamp
    2. Appending the new date and message string to alonehistory.txt
    3. Redirecting back to alone.php
    From here, the cycle may continue again as long as the client is sending messages to alonesave.php.

Your main file must be named alone.php, whereas your processing file must be named alonesave.php. Your JavaScript file must be named alone.js, and your CSS file must be named alone.css. Additionally, for this assignment, you are required to have a file called alonehistory.txt which will contain all of the chat messages sent to the chat.

Notes

The timestamp that you prepend to a message should be in the form: (MM/DD/YYYY @ 24hr-time), e.g. (11/16/1974 @ 1300), (10/13/1961 @ 0900), (02/23/1964 @ 2010). Information for using PHP's date function is located at http://php.net/manual/en/function.date.php. Date string "m/d/Y @ Hi" should help.

Do not use any HTML or JavaScript redirects. All redirects are to be handled by PHP. This can be accomplished with header("Location: alone.php"); . This function allows you to add a raw HTTP header that gets sent back to the client.

Scrolling to the bottom of the chat window is accomplished using the 'scrollTop' and 'scrollHeight' DOM attributes. Both divs and textareas have these attributes and, by setting the element's scrollTop to its scrollHeight will automatically scroll the element as far down as possible (e.g. aDivInYourCode.scrollTop = aDivInYourCode.scrollHeight;). Hint: you may consider utilizing the window.onload event handler in your JavaScript code.

As usual, your HTML output is still required to be valid HTML5. Validation will be done through http://validator.w3.org.

Hints

For file reading and writing in PHP, we recommend the functions file_put_contents and file_get_contents.

Homework Submission

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