Programming Assignment 4
PHP Scripting

Due on Thursday March 6 before midnight


The goal of this project is to learn server-side web programming using PHP. More specifically, you will develop an e-commerce web application where customers can buy products listed by the eBay Commerce Network API for Shopping.

This project must be done individually. No copying is permitted. Note: We will use a system for detecting software plagiarism, called Moss, which is an automatic system for determining the similarity of programs. That is, your program will be compared with the programs of the other students in class as well as with the programs submitted in previous years.

Note that, if you use a Search Engine to find similar programs on the web, we will find these programs too. So don't do it because you will get caught and you will get an F in the course (this is cheating). Don't look for code to use for your project on the web or from other students (current or past). Just do your project alone using the help given in this project description and from your instructor only.


As in Projects #2 and #3, you will develop this project on the Omega web server and you will test the project on your PC/laptop using the Mozilla Firefox web browser. Login on using SSH and do the following:

cd public_html
tar xfz project4.tgz
cp project3/.htaccess project3/.htpasswd project4/
cd project4
The project4 directory contains the file buy.php, which needs to be changed as described in the description of the web application.


The following are tutorials on PHP. Use them as a reference only.

You will use PHP sessions and the PHP SimpleXML interface. Using SimpleXML, to access all children of $x with tag A, use $x->A. To access the value of an attribute A of an element $x, use $x['A']. To store a SimpleXML value $x in the $_SESSION, you need to coerce it to a string first using (string)$x.
$xmlstr = file_get_contents('');
$xml = new SimpleXMLElement($xmlstr);
foreach ($xml->BookList->BookData as $b)
    foreach ($b->Prices->Price as $p)
        if ($p['store_id'] == "amazon")
            print $b['isbn'] . ' ' . $b->Title[0] . ' ' . $p['price'] . "\n";

Project Requirements

You will develop a trivial web application that allows customers to buy products. You need to reverse-engineer my PHP script:
by filling out its forms and by looking at the HTML source that is generated by this script. Your task is to modify your own buy.php script in your project4 directory on Omega to make it behave in the same way as my buy.php, although you should make your script generate better HTML code to look nicer.

You will use the API for shopping. The eBay Commerce Network API ("ECN API") is a flexible way to access and recreate practically everything you see on First, you need to get an API key. You can use the default key. We will only use the "Search by keyword" method from the eBay Commerce Network Publisher API Use Cases.

The result of a keyword search typically contains 5 products that best match the keyword query. Each product contains a link productOffersURL to the web page that gives a detailed description of the product and a list of best offers from various sellers. So each product has a range minPrice - maxPrice of the prices offered by these sellers. We will ignore the list of offers and we will assume that when we buy this product we pay the minPrice.

You need to use a PHP session to store the shopping basket (the list of chosen items throughout the session) as well as the results of the last search. For each chosen item, you store the Id, the name, the minPrice, the first image, and the productOffersURL (the link to the web page that lists the best offers for this item). Your PHP script must be able to handle the following query strings:

Hints: you can use the PHP function print_r for debugging. It prints human-readable information about a variable.

What to Submit

Important: In a comment on top of your buy.php file, put your name, your student ID, and your URL address to run your web application, such as Use the form below to submit your buy.php file. We do not accept email or hardcopy submissions. You may submit your files as many times as you like, but only the most recently submitted files will be retained and evaluated (newly submitted files replace the old files under the same file name). After you submit the files, please double-check that your submitted files are correct by clicking on the Status link.

Submit Project #4:

Last modified: 02/15/14 by Leonidas Fegaras