Você está na página 1de 3

CSC2720

Assignment #2

Due: 26th Feb 2010

Objective
The objective of this assignment is to let you practice using different methods to maintain application states across multiple server-side scripts.

Specification
Let M = number of items to be listed per page by "list.php". Implement four PHP scripts that behave similarly to 1) http://www.cse.cuhk.edu.hk/~cjyuan/csc2720/asgn2/login.php - If the request method is POST o Retrieve the user-id and password from the request o If the user-id and the password pass the authentication Display a welcome message Else Display an error message and ask the user to re-enter the user-id and password - If the request method is GET o If a user is already logged on Display a welcome message Else Ask the user to enter a user-id and password 2) http://www.cse.cuhk.edu.hk/~cjyuan/csc2720/asgn2/setting.php - If the user has not yet logged in o Ask the user to log in first - Else o Retrieve the value of M from cookie o If the cookie does not exist, set M to 20 o If the request method is POST Override M with the value retrieved from the request o If M < 5, set M to 5 o Update the value of M in the cookie o Use a text field (with initial value set to M) to collect a new value of M from the user

3)

http://www.cse.cuhk.edu.hk/~cjyuan/csc2720/asgn2/list.php - If the user has not yet logged in o Ask the user to log in first - Else o Retrieve the value of M from cookie o If the cookie does not exist, set M to 20 o Display M records on the selected page. (Default is page 1) All except the last page should contain exactly M records. Last page can contain less than M records. o Display at the bottoms some links or buttons to allow the user to access different pages http://www.cse.cuhk.edu.hk/~cjyuan/csc2720/asgn2/logout.php - If a user is currently logged in o Log the user out - Redirect the client to login.php

4)

TOP Menu "login.php", "setting.php", and "list.php" share the same top menu, and the menu has the following behavior: - If a user is currently logged in o Display "Hi! <user-id>" in the first menu item o Display a link to "logout.php" in the 4th menu item - Else o Display a link to login.php in the first menu item o Do not show anything in the 4th menu item Users The two sets of user name and password are: 1) User name: john, password: 123 2) User name: jane, password: 456

Notes: 1. Your web application does not need to look exactly the same as the sample web application. 2. The file asgn2_inc.php contains a. getdata() a function that returns an array of 212 randomly generated records as an array of arrays. The following example illustrates how you can manipulate the returned value: <?php require_once("asgn2_inc.php"); $data = getdata(); $ndata = count($data); // # of records in $data[] for ($i = 0; i < $ndata; $i++) { // To output the 'id' and 'phone' of record $i $id = $data[$i]['id']; $phone = $data[$i]['phone']; echo "Record $i: $id $phone<br/> \n"; } ?> b. login() a function that can be used to authenticate the user. 3. If you make any assumptions in your implementation, please type them in a separate text file named "readme.txt". 4. You may introduce additional files as you see fit. For examples, a CSS file, a PHP script that implements the top menu, etc.

What to submit?
Zip all your files, including "asgn2_inc.php", into "asgn2.zip and submit the file to Moodle.

Você também pode gostar