IELM 511 Information Systems Design Lab 3: Fundamental PHP Functions: I
IELM 511 Information Systems Design Lab 3: Fundamental PHP Functions: I
This lab will use a few exercises to build up your experience with PHP scripts. The main
structure will remain the same: we will get inputs via forms submitted by a web client, and
the CGI program (in php) will do something with the data sent from the client, and return
HTML output back to the client. We will focus on some basic language skills for PHP.
There are several websites with excellent introduction to PHP, including most functions
and several examples and tutorials. You should use your favorite one while doing this lab.
One such site is: http://www.w3schools.com/PHP/
Lab tasks: The tasks of this lab should be done in three stages.
STAGE 1. In this stage, you will try out many simple PHP programs to learn the basics of
PHP language. Each program should be tested by running it as a CGI script.
Step 1.1. Make a simple web-form (file: run_cgi.html) with one input field and one
text-box field (use or modify the file given to you in the lab materials).
Step 1.2. Write a simple PHP program (run_cgi.php) that will respond when the form from
step 1.1, which will merely respond back to the client: “Hello, world.”
Use the following code in your CGI program and observe the results.
$paper_auths = array( “P111” => “Alpher, Bethe, Gamow”, “P222” => “Gauss”);
$paper_auths[‘P333’] = “Newton, Raphson”;
foreach ($paper_auths as $p_no => $auths) {
echo “Paper number “ . $p_no . “ is authored by “ . $auths . “. “;
}
STAGE 2. In this stage, you will learn how to set up PHP so it can send emails directly
using CGI programs.
Step 1. Setting up your email server and windows environment (1)
Go to [root disk]\xampp\apache\bin\php.ini.
Remove “;” before each blue line listed below.
[mail function]
; For Win32 only.
SMTP = (e.g., smtp.ust.hk)
smtp_port = 25
; For Win32 only.
sendmail_from =(e.g., [email protected] )
; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
sendmail_path = “C:\xampp\sendmail\sendmail.exe -t”
(2)
Go to [root disk]\xampp\sendmail\sendmail.ini.
Remove “;” before each blue line listed below.
smtp_server=(e.g., smtp.ust.hk)
; smtp port (normally 25)
smtp_port=25
auth_username=(e.g., ust account)
auth_password=(e.g., ust passward)
force_sender=(e.g., [email protected] )
Setp 2. Download “sendmessage.htm” from the folder “lab3_files” and save it in [root
disk]\xampp\htdocs\html\;
Download “sendmail.php” and save it in [root disk]\xampp\htdocs\html\cgi-bin;
Setp 3. Comprehend the function of each file. In sendmail.php, modify the first argument
of the mail( ) function to replace [email protected] to your own email address.
STAGE 3. Using the functions developed earlier, write a PHP program that will do the
following.
Suppose we have the data for a set of papers: each paper has a paper number, the names of
one or more authors, and one keyword (denoting the main field of this paper). Store this
data in two associative arrays: one array called $paper_authors, and one called
$paper_keywords. To simplify the programming, just use the last name of the authors.
We are also given a list of reviewers: for each reviewer, we know the name, and a list of
keywords, denoting the fields of expertise of this reviewer. Store this data in an associative
array, $reviewers, indexed by the name of the reviewer. e.g. there may be an entry like:
$reviewers[‘anton’] with value “cg, cad”.
It is possible that the same name appears as an author as well as a reviewer. We shall
assume that all names are unique.
Write a program to suggest which reviewer is eligible to review a given paper. The
conditions are: (1) the person who is assigned should have the paper-keyword in his
expertise-keyword list and (2) the reviewer should not have any co-authored any paper with
any of the authors of the paper.
The inputs: In this lab, we will assume that the data for the papers and reviewers are
already stored in arrays in your program (these are the two array constants in the given
skeleton program). We will send two additional inputs to the CGI program: (a) A paper
number, and (b) an email address (of the area editor, in this case, you). Modify the given
HTML file to design the proper form to send this data to your CGI.
The output: For the input paper number, your CGI program must find out the list of eligible
reviewer names, and (i) send an email to the area editor, listing the names of all possible
referees for this paper; (ii) Output the same data also to the web client.
References:
1. HTML quick reference file.
2. PHP tutorials and function references: (from www.php.net)
3. PHP tutorial site: http://www.w3pop.com/learn/view/p/3/o/0/doc/php_ref_string/
4. Another PHP tutorial/reference: http://www.w3schools.com/PHP/php_ref_array.asp
Lab materials for IELM 511 prepared by WEI Xiangzhi, Dept of IELM, HKUST.