Setup CGI Applications with Available Free CGI Scripts
Is CGI easy? Of course it IS for users who have good computer background and
know CGI pretty well. How about the users who are not good at programming? Ohh?!
Some readers without much programming experience may be stunned by the list of
contents even before they seriously begin to work on it and give up. Their
reasons sound perfect: they don't know the annoying PERL or C, and most
important, they even don't want to learn them. Can these people set up their own
CGI application? The answer is YES. When I first set up my own CGI applications
(textclock, countdown, and Formail) in 1996, I was so excited to see how great
they were working. But unforunatly at that time I even didn't know how to
program with PERL, what CGI really was. But anyway, they run perfect and they
were made by myself! That's made me crazy!
Most often, the CGI users are not programmers. They include CGI applications
in their web pages to add some useful features, or just make their web pages
look cool. It's not neccessary for them to know every details of CGI and
programming. They can easily take other people's works and use them directly.
In fact, there are lots of web sites which maintain free CGI scripts that can
be freely downloaded. Usually these sites also provide the README files to help
you set up your own application. What you need to do is just download the script
to your server (modify some system parameters is necessary), follow the README
file step to step. It will work!
One of the best sites that provide free CGI scripts is Matt's Script Archive. In this
site, there are many useful CGI scripts such as Guestbook, Formail,etc written
in several programming languages such as PERL and C. We thanks to Matt
Wright for his great efforts to provide so many useful CGI scripts for us.
In this lecture we will use Matt's Script Archive 's PERL scripts as
examples.
Note the following examples are directly downloaded from Matt's
Script Archive, unlike the examples in prevoius lectures where the codes are
developed by myself.
Download Site Genearl InformationLet's see how we can go to the
download site and get helpful information. Let's take Guestbook as an example.
First go to the Matt's Script
Archive main page. Then click the Guestbook in the Matt's Perl CGI
Scripts catagory, you can get to this site: http://worldwidemart.com/scripts/guestbook.shtml.
Usually, you can get the following content:
- Overview - what this application is and its main function
- Readme - How to set up the application
- Downloading - files need to download
- Working Demo - examples
- Frequently Asked Question - help and debug
- etc..
Textclock
Let's start with this simple one. It is nothing but when you click Get
Textclock Time, you can get the current date and time.
Let's see how to do that:
- First go to the Matt's Script
Archive main page.
- Then click the Textclock in the Matt's Perl CGI Scripts
catagory, you should get here : http://worldwidemart.com/scripts/textclock.shtml.
- Go to the Downloading and transfer the textclock.pl to your machine and put it in a directory that
have permission to execute CGI.( Reference to Where to Put
CGI Program lecture). You'd better first ask your system administrator or
webmaster to make sure which directory can run CGI program. For this example,
I put this file in the /home/CGITutorial/cgi-bin
directory in my machine, which has permission to execute CGI.
- Change the textclock.pl's mode to be executble
issuing the following command:
chmod 755 textclock.pl
- Now embed an anchor in your home page:
<a href="cgi-bin/textclock.pl"> Get Textclock Time</a>
- The above source code look like this in your homepage:
Get
Textclock Time
Now when you click the above Get Textclock
Time. It will work! Note here no input for the CGI scripts so we need no
FORM. Get an try by yourself. If everythig is correct, it should work!
Countdown
Countdown is an interesting CGI program which allows you to countdown to a
specific date of your choice (e.g., holidys, birthdays, anniversaries).
Here are the steps:
- First go to the Matt's Script
Archive main page.
- Then click the COUNTDOWN in the Matt's Perl CGI Scripts
catagory, you should get here : http://worldwidemart.com/scripts/countdown.shtml.
- Go to the Downloading and transfer the countdown.pl and countdown.html to
your machine and put countdown.pl in a directory that
have permission to execute CGI. Here I still put both files in the /home/CGITutorial directory in my machine, which has
permission to execute CGI.
- Change the countdown.pl's mode to be executble
issuing the following command:
chmod 755 countdown.pl
- Now we need to modify the countdown.html:
<html><head><title>Countdown Examples</title></head>
<body><h3>Want to know how long till the year 2010?</h3>
<a href="cgi-bin/countdown.pl?2010,1,2,0,0,0">Countdown to
the year 2010!</a>
<p>
<hr>
<p>
Or make your own date!!!
<form method=GET action="http://your.domain/cgi-bin/mattw/countdown.pl">
<input type=text name=""> (Format: yyyy,mm,dd,hh,mm,ss)
<p>
<input type=submit>
</form><p>
<hr>
<p>
<a href="http://your.domain/cgi-bin/countdown.pl">Get the default
countdown!</a>
<p>
<hr>
<p>
<h3>Ignore the # of seconds in countdown to 2010</h3>
<a href="http://your.domain/cgi-bin/countdown.pl?2010,1,2,0,0,XX">Countdown to
the year 2010!</a>
</body></html>
Change the above red URL to whatever your countdown.pl locate, here it is: cgi-bin/countdown.pl
- Save the modified countdown.html.
Now when
you open the countdown.html
page, it will work. If there's any problems, see the README or FAQ for help.
FormMailFormMail is a generic web-based form that can send any message
to the specified email address.
Let's see how to do that:
- First go to the Matt's Script
Archive main page.
- Then click the FORMMAIL in the Matt's Perl CGI Scripts
catagory, you should get here : http://worldwidemart.com/scripts/formmail.shtml.
- Go to the Downloading and transfer the FormMail.pl to your machine and put it in a directory that
have permission to execute CGI. For this example, I still put this file in the
/home/CGITutorial/cgi-bin directory in my machine.
- There's one line we need to modify in the FormMail.pl:
@referers = ('worldwidemart.com','206.31.72.203'); This should
change to your machine's Domain name and IP address. This
statement is there mainly for security reason.It prevents the user from other
machine to use your scripts. So I change to my server: @referers = ('zhanshou.hypermart.net',' 63.251.5.138');
- Change the FormMail.pl's mode to be executble
issuing the following command:
chmod 755 FormMail.pl
- Create a HTML Form file "formmail.html":
<html>
<head><title>Send Your Comments</title></head>
<center><h1>Send Your Comments</h1>
<form method=POST action="cgi-bin/FormMail.pl">
<INPUT TYPE=HIDDEN NAME="recipient" VALUE="zhanshou@hotmail.com">
<INPUT TYPE=HIDDEN NAME="subject" VALUE="CGI Tutorial Feedbook">
<PRE>
Your Name: <INPUT NAME="realname" TYPE="TEXT" SIZE="20" MAXLENGTH="30">
E-mail address: <INPUT NAME="email" TYPE="TEXT" SIZE="20" MAXLENGTH="30">
Your comments :
<TEXTAREA NAME="comments" ROWS="4" COLS="30">
</TEXTAREA>
<INPUT TYPE="SUBMIT" VALUE="Send"> <INPUT TYPE="RESET">
</PRE>
</form>
</html>
Note that the zhanshou@hotmail.com is the email
address where you want people to send you this message.
- Now when you open the formmail.html
page, it will work!
The FormMail is a very powerful application. It
has lots of addational features if you specify the parameter correctly. You can
reference README file for more details.. It will tell you how to set up other
useful feature.
WWWBoard
WWWBoard is a discussion message board that allow people to post questions
and answers.
Web Search Engine
Web Search Engine is a search engine that allow people to search the web
pages under specified root directories. For example, you can set up a search
engine that search all the pages under the "www" dirctory in your web server.
The search
engine in "Table of Content" page of this tutorial was set up with Matt's
Script. Click
here to run search engine.
TextCounter
There is a working example in "Table of
Content" page of this tutorial to record the page hits.
Random Text and Random Image
Each time you load the pages, the text and the image are randomly displayed.
|