Programming Assignment 2
PHP Scripting

Due on Thursday February 24 before midnight


This project must be done individually. No copying is permitted. 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 Google's Search API for Shopping.


For this project, you will use the Omega web server. Login to Please call UTA OIT if you have problems with your omega account. Look at your path using the unix command pwd. For example, if your username is xyz1234, you will see:

In the following, replace the path /home/x/xy/xyz1234 with your own path. Then, you do the following on omega:
cd public_html
tar xfz project2.tgz
cd project2
Then edit the file .htaccess (note: it starts with a dot) inside the project2 directory using your favorite editor (vi, emacs, etc), and change the line
AuthUserFile /home/x/xy/xyz1234/public_html/project2/.htpasswd
to point to your own path. Then do:
htpasswd .htpasswd xyz1234
(use your username instead of xyz1234). It will ask you for a password twice. This is the password you use when you run your PHP scripts on a browser. It already contains a password for the GTA; so the GTA can run the script of any student but you can only run your own script. For this project, you should put your PHP files in the project2 directory only. You can test your setup on your web browser by using the URL address:
(use your username instead of xyz1234). Note that if a script doesn't require GET/POST parameters, then you can test it by running it on omega using php. For example, php buy.php


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

You will use PHP sessions and the PHP JSON interface. Here is a script that uses sessions:
if (!isset($_SESSION['count']))
    $_SESSION['count'] = 0;
print 'you have visited ' . $_SESSION['count'] . ' times';

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 public_html/project2 directory on Omega to make it behave similarly to my buy.php.

You will use the Google's Search API for Shopping. Read the Search API for Shopping. To use this web service, you will need a google shopping access key. You may use mine, available at passwords.txt, but is better to request your own from here.

You need to use $_SESSION to store the shopping basket (the list of chosen items throughout the session) and the results of the last search. For each chosen item, you store the googleId, the title, the price (the first price, if they're many), and the link of the seller's web page that features this item.

Your PHP script must be able to handle the following query strings:

Note: Like in the first project, you should not use any tool that generates code. You only allowed to use a text editor to write your scripts. Hint: you may need to use the following PHP functions: file_get_contents, urlencode, json_decode.

What to Submit

Important: On top of your buy.php file, write the URL on Omega to use to run your program (eg. Use the form below to submit your buy.php file. You may submit your file as many times as you like, but only the most recently submitted file will be retained and evaluated.

Submit Project #2:

Last modified: 02/16/11 by Leonidas Fegaras