CSci 4608 Problem set 3 (project): php, cookies, session, database
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:
Each page must have:
- A welcome page which explains what the site is about.
- 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
- A login page (a form with just the name and the password).
- 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
- 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.
- 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.
- 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.).
- 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).
- 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).
- Clarification (posted Nov. 9th): HTTP
forms (see examples of drop-down boxes). On the PHP side, if your
drop-down box has a name 'box', then
$_POST['box'] will give you the value selected by the user.
- Whenever possible, the results should be formatted by
tables. Table headers <TH> must be provided.
- If a country has a
flag picture, that picture should appear next to the country, same for
sports graphics. For the comparison page the pictures should appear
only if available for both countries.
- If there are more than 20 rows of results, only the first twenty
are displayed on the first page, and the link NEXT is provided for the
next page of results. That page should have a PREVIOUS link (and NEXT
link if needed).
- A header, consistent with the name of the page in the navigation
- 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
- 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).
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
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:
- You may, if you prefer, separate user information into several
- It's OK if you keep just a total number of pages the user has
visited TOGETHER with the submitted forms, you don't need to separate
it into counts for individual pages.
- You may store just an IP address of where the user is coming
from or the domain name, it's up to you which one you store.
- Users with the same name but different domain/IP addresses may or
may not be considered the same person, this decision is up to you, as
long as it's consistent for all users and documented.
- If you have other questions about this, please ask.
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).
- Read the whole file in, line by line, storing the file information
either in the program itself (in a variable or in an array indexed by
line numbers) or in another file.
- When you get to the line that needs to be updated, change the
information there before you store it, and then continue reading and
storing the rest of the file. You can also use the function file()
(see below) to read the whole file into an array.
- When you get to the end of the file, write the stored data back
into the file, or, if you were storing data in another file, rename
the file back to the original name.
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
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.
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
Make sure to provide the navigation bar or a back link to the request
pages so that the user can submit other requests.
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.
Please answer the following questions (on your Wiki page or in an
- Which programming aspects of PHP have you found to be the most
helpful? Which features seemed confusing or difficult to use?
- Did you notice any capabilities of PHP that are not present
in perl? Did you notice any capabilities of perl that are not present
in PHP? If yes, what are they? Note that perl actually supports
MySQL access and cookies, we just haven't used it for the perl problem
- Which of the two server-side languages (perl and PHP) would you
recommend in what circumstances?
- Would you recommend using CSS to set the style of pages generated
by PHP, or would you set the styles/colors/fonts directly? What are
the tradeoffs between the two?
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.