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: omega.uta.edu. On omega.uta.edu, 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:
/home/x/xy/xyz1234In the following, replace the path /home/x/xy/xyz1234 with your own path. Then, you do the following:
cd public_html wget http://lambda.uta.edu/cse5335/project3.tgz tar xfz project3.tgz cd project3 ls -aThen 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/.htpasswdto 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:
http://omega.uta.edu/~xyz1234/project3/buy.php(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 omega.uta.edu, 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.
<?php session_start(); if (!isset($_SESSION['count'])) $_SESSION['count'] = 0; $_SESSION['count']++; print 'you have visited ' . $_SESSION['count'] . ' times'; ?>
You will develop a trivial web application that allows customers to buy products. You need to reverse-engineer my PHP script:
http://lambda.uta.edu/cgi-bin/php/buy.phpby 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:
buy.php?search=digital+cameraThis should call the web service request https://www.googleapis.com/shopping/search/v1/public/products?key=xxx&country=US&q=digital+camera, where xxx is your google shopping access key. The web service results will arrive in JSON format (if you specify &alt=atom in the query string, the results will come in XML, but Omega has problems parsing XML). To see how the JSON data look like, cut and paste this URL on your browser and look at the reply.
buy.php?buy=7145898469780330726Your script should look at the results of the last search stored in $_SESSION to find the item under this googleId and should copy it into the shopping basket.
Hint: you may need to use the following PHP functions: file_get_contents, urlencode, json_decode.
Important: On top of your buy.php file, write the URL on Omega to use to run your program (eg. http://omega.uta.edu/~xyz1234/project3/buy.php). 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.
Last modified: 02/07/12 by Leonidas Fegaras