CSci 4608 Problem set 3 (project): php, cookies, session, database access

Due Thursday, November 11th, at 8pm

General guidelines, submission, etc.

This problem set will be done in groups of two. The front page of your web site should be linked from the Wiki from this page under your project group name. Please attach all the php files that you have created for this problem and all the graphics files you used (except those that were referenced by the database) to the Wiki page.

Use your account on epoxy2 to work on this problem set. A group may use any one of their two accounts.

Important: the quality of code matters a great deal for this problem. Use variables, functions, include/require statements, and make sure that your code is clear, easy to read, and easy to modify. Quality of code will be a substantial part of your grade.

Web site description

For this problem you are to design and implement a small (3-4 pages) web site. The web site contains the results of Olympic Games in Athens, 2004. It will generate pages based on the data contained in MySQL database on epoxy2. The description of the database tables and sample queries and all needed information about epoxy2 is posted here. The database access information will be announced in class.

The web site should have the following:

  1. A welcome page which explains what the site is about.
  2. A user registration page with a form that asks for the user's first and last name, a password, preferences for the web site appearance (to allow the user to choose between the two site designs), whether the user's browser supports cookies (don't try to check it yourself, just allow the user to specify it) and some optional information, such as the user's home country and the city. Use server-side verification to make sure that the first/last names are not empty and contain letters and spaces only (any combination of upper/lower case is OK) and that the user's preferences are specified. If the data is incomplete, display a page with an error message and the link back to the form. Set the form's values to the correct information submitted by the user when he/she filled in the form originally.
  3. A login page (a form with just the name and the password).
  4. A page (or several pages) that allows the user to find out various information about the results of the olympic games. Only registered users may or those who have successfully logged in can view this information. More specifically, the user should be able to display the following:
    1. The user is given a pull-down menu of all sports (generated from the current list of sports in the database). Choosing a sport displays all medals in that sport in all categories for all countries and the totals for each country and each category.
    2. The user is given a pull-down menu of countries. Choosing a country displays all medals for that country in all categories and all sports. Note that categories may be different for different sports.
    3. The user is given a pull-down menu of sports, another one of a category (such as mens or womens), and a text input to enter a number (n). The result is the best n countries in this sport in the category with all their medals (in decreasing order by the number of medals, ties in gold medals are resolved by the number of silver ones, etc.).
    4. The user is given a pull-down menu of countries. Choosing a country gives all the sports/categories in which this country has any gold medals (and the number of medals).
    5. The user is given two pull-down menus of countries. Choosing a country gives the total numbers of gold, silver, and bronze medals for these countries, side-by-side (for the purpose of comparison).
    Some resources: Formatting results:
Each page must have:
  1. A header, consistent with the name of the page in the navigation bar.
  2. A navigation bar (to link it to other pages), identical for all pages (include the file). The navigation bar may be at the top of the page or on the left side. Extra credit: make one design with the navigation bar on top of the page, and the other one that has it on the left side of the page.
  3. A footer: authors' names, mention of 4608 course and a link to it (in case someone stumbles upon your web site and confuses it with a real Olympic Games web site).

Part 1

You will write two different designs for your web site. The designs must differ in page layout and colors and/or fonts. You may represent different layouts as CSS or as variables directly in php code for your pages. Use separate files to define your designs and use include() or require() (or include_once(), require_once()) php functions to include the files.

Part 2

Set up a file to keep track of the users. Specifically, record their name, their preferences, the domain the person is coming from, and how many times the user has accessed a page or submitted a form (you don't need to record any form data).

When a user first registers at the registration page, generate a user ID (if the user is new), store the user information (including the ID) in the file and keep updating it as the user browses the web site. Set a long-term cookie with the user's ID and preferences for the site design. If the user is a returning one (i.e. already has the cookie), just keep updating the user information in the file. If the user doesn't have a cookie, but has the same name as a previously registered user, then check the password to make sure that user is the same person. If the user is not new (i.e. there already is a user with such name), send the cookie with the user's ID.

Clarifications (posted Nov. 5th):

Another clarifications (posted Nov. 6th): Since there is no way to update a file in php (i.e. just to change a value in one specific part of the file without changing anything else), the way to change a user's information (such as to increment a counter) is the following: Some helpful php functions are: file (reads entire file into an array indexed by line numbers), rename (renames a file or a directory), unlink (deletes a file), fwrite (writes a string into a file), file_put_contents (writes a string to a file, automatically opens and closes the file).

Please ignore issues of concurrent writes (i.e. two php scripts writing to the same file at the same time, overwriting each other's data). Assume that concurrent writes don't happen in this small appication, so you don't need to worry about them.
End of clarification Nov. 6th
Submitting this part of the project: Please provide a link to your file(s) with an explanation of what's stored in each one. The files must be publicly readable. You may, if you prefer, write a php file separate from your web site that displays the contents of the user information files and include this link in your submission. This will give you a few points of extra credit, but work on it only after you are done with everything else.

Part 3

When the user registers at the registration page or a user with a long-term cookie comes back, set up a session for that user. If the user indicated that his/her browser doesn't support cookies, use extended URLs instead.

Part 4

Write the page(s) with the forms to submit the user requests (as described above). At least one of these pages should display information about all sports and the sport icon. The description is stored in the field description in the table Sports.

Make sure to provide the navigation bar or a back link to the request pages so that the user can submit other requests.

Part 5

We may change the data in the database (adding another sport, deleting a country, and so on) so that you can check that your program doesn't have any hard-coded information in it (all pages are generated based on the data in the database). We will announce in class and by e-mail when such changes take place.

Part 6

Please answer the following questions (on your Wiki page or in an attached file):

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.