Programming Assignment 3
PHP Scripting

Due on Thursday February 16 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 Eclipse connected to the Omega web server. Please call UTA OIT if you have problems with your omega account. On Eclipse, select Window -> Show View -> Other... -> Remote Systems. This will create a Remote Systems menu at the right. On this menu, R-click New -> Connection. On the new connection, click on SSH Only and use Host name: On, R-click on Ssh Terminals and choose Launch Terminal. At the Terminals session, 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:
cd public_html
tar xfz project3.tgz
cd project3
ls -a
Then edit the file .htaccess (note: it starts with a dot) inside the project3 directory using your favorite editor (vi, emacs, etc), and change the line
AuthUserFile /home/x/xy/xyz1234/public_html/project3/.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 project3 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

On the Remote System menu, in the item, click on Sftp Files -> My home -> public_html -> project3 and R-click on buy.php and use Open With -> PHP Editor. Now you can edit your PHP script.


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/project3 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:

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 #3:

Last modified: 02/07/12 by Leonidas Fegaras