Project 5 - Cookies & Databases
Overview
We will be modifying the script from project
4 to make use of more advanced CGI techniques. Have you
ever been to a site that remembered you on return visits?
It's all the rage, so let's see how it's done...
Preparation
Objectives
- Learn how to use cookies
- Work with a database
Script Details
Make the following changes to the script from project
4:
- After all information has been submitted, set a cookie
assigning a unique identifier to the user.
- In addition to emailing the final results, save them to
a database.
- If the user tries to access the script again, print a
message telling them that they have already submitted the
form and display the information they originally submitted.
(hint: use the cookie!)
Demo
script
Notes
- You can use any type of database for this project (flat
file, DBM, SQL)
- You may use a CGI library to simplify the cookie setting
(cookie-lib.pl or CGI.pm, for example)
For those of you wanting to use MySQL on the ACC servers,
it is indeed functional but you will need to include this
line in your Perl script (prior to use
DBI;):
use lib "/usr/lib/perl5/site_perl/5.005/i386-linux";
Keep in mind that this server is not quite what you'd get
if you were working on a real ISP. All of us have essentially
root access to the MySQL installation and we can create our
own databases. However, all of them are stored in a single
place, so there can't be more than one with the same name.
(That place is /var/lib/mysql
if you want to see which names are already taken.)
Also, if you don't set a login name and password for your
database, anyone on the system can edit it (or delete it!).
On most ISPs you would request a database from your tech support
and they would set it up for you with the appropriate login
and password.
A good book on MySQL is MySQL
& mSQL by O'Reilly, and I also recommend the Perl
DBI book from O'Reilly if you plan to use Perl to interface
to your databases. (yes, I like O'Reilly!)
Finally, here is a good article illustrating how to set up a MySQL database
Project Submission
You should have a link to the functional script from your
main project website. Email the text of the script and the
working URL to cgi@iteachu.com
by the deadline date in the schedule.
Jump
to Forums [Project 5]
|