CGI banner

Understanding CGI and PERL

CGI or Common Gateway Interface is just a name for the interaction of a browser, and a non-static program on the Internet. By non-static, I mean that the page you load, does’t load the same every time you load it. CGI uses documents called scripts to obtain things called libraries or bins that parse the information given to them. The CGI scripts can be written in a variety of languages, but the most widely used is Perl.

If you haven't already, view my quick introduction to perl. In this Intro, you will learn the "abc's" of perl and how it works.

Before we start the dirty stuff, you will have to crack open a simple text editor (Notepad, TeachText, etc...). A simple word processing program. All you need is the ability to type text in and save it as a ASCII text file.

So when you are ready, just open up that editor and start with a blank page.

The "pound bang" line goes on the beginning of every Perl Program. It looks like this:

#!

This line tells the operating system that it must send this data to an interpreter. What ever follows the pound bang, is the file path to the interpreter. Usually the interpreter is located in the /usr/bin/ directory. In this case the Perl interpreter, which on many machines is located in the: /usr/sbin/ directory.

So your first line should look something like this:

#!/usr/sbin/perl

The next step is to decide what our nifty program is going to do. It is a good idea to plan your program out, so your not confused what to write while your actually programming it. So, right now, lets decide what this program will do.

I've written a quick HTML form that will work with your program so just cut and paste it to your editor and save it as mylog.htm.

 

<html>
<head>
<title>MyLog Entry Form</title>
<body>
Please fill in the below information<br>
<form action="/cgi-bin/mylog.cgi" method=POST>
<!- Make sure the action value is the exact path where you want to keep your script -!>
Your Name:<input type=text size="20" name="usrname"><br>
Your e-mail: <input type=text size="20" name="email"><br>
Comments:<br>
<textarea cols="40" rows="3" name="comments"></textarea><br>
<input type=submit name="submit" value="submit"><input type=reset name="reset" value="reset">
</form>
</body>
</html>

Here is a list of what our program will actually do:

1. mylog will control an HTML form that asks for a user's name, e-mail and ask for some

comments.

2. mylog will decode and parse that input from the form.

3. mylog will return the user a thank you screen using some of the user's input.

4. mylog will send you (the maintainer) an e-mail reporting that someone filled in that form.

5. mylog will create/append a log file, writing each entry in a formatted, logical manner, so

that you can user that information.

 


Previous PageNext Page