Tripod Tripod
New Users:  Sign Up    Members:  Log In
 
HOME
   help

CGI and Modules Definitions
Introduction    CGI and Modules Definitions    Module Specifics    Print

CGI

CGI Definition

An abbreviation for Common Gateway Interface, CGI refers to the way in which most Web servers communicate with scripts or programs. CGI is most commonly used in forms requiring the user to input information. This data is put into an HTML form by a script and can be utilized by the programmer in various ways. Perl is the language most commonly used to write CGI scripts; all of the scripts in the CGI Library are written in Perl. CGI is not itself a programming language; it's more of a protocol for communication between the Web server and a script.

Modules Definition

Using Perl Modules on Tripod. Modules are a great way to add functionality to your scripts without having to do all the work yourself. After all, if somebody else has done the job of figuring out how to read CGI input from a form, or calculate which of two dates is the earlier one, why shouldn't you benefit from his or her work?

Here at Tripod, we've already done the work on a few modules that we think might be useful to you. Simply click on the module name to learn the general way these modules work, and you can start using them in your scripts. You'll also want to read the instructional comments at the beginning of any module that you decide to use, as they will give you more specifics about the functions the module provides.

You can use modules written by other people (including yourself) in your scripts, as long as you copy them into your cgi-bin directory. Be aware that not all modules work the same way Tripod modules do, so you may need to do some additional work to figure them out. For starters, all modules used on Tripod must be written in Perl. If modules contain code other than Perl, they simply won't work on Tripod.

A Good Example of how Tripod modules differ from others:

CGI is frequently used for e-mailing purposes, whether it be a site manager sending e-mail to visitors or information compiled from a site's forms being mailed to the site's owner. In order to do either task, a script needs access to an e-mail program. Tripod has provided its users with a module called TripodMail.pm. However, Tripod's mail module doesn't function exactly like the mail programs you may have used before. You need to have a mail template in your directory which contains the normal fields, such as "To," "From," and "Subject." You can include variables in that template. There is a method of the TripodMail.pm module called "sendMail." This method needs two bits of information: the name of the mail template in your directory, and a hash of variables. These are the same variables that are referred to in your template. Say you had a template that looked a bit like this:

To: $recipient
From: $sender
Subject: $subject

$body

$signature

You could then use the TripodMail module to send e-mail by creating a new instance:

require TripodMail;
$mail= new TripodMail;
$mail->sendMail($template, /%hash);

In this case, "$template" is the name of the template file, and "%hash" is a hash of variable mentioned in the template. The hash for the template about should include a recipient, sender, subject, body, and signature in the hash of variables. That hash would be built elsewhere in the script that's calling the TripodMail module. For example, if this bit of code were in a guestbook script, that script would collect information from a form (where the visitor actually signed the book). Along with building a new entry in your guestbook, the script would also store the visitor's e-mail address in your hash as "recipient," and your e-mail address as "sender."

One important thing to note is that TripodMail is not the same thing as a mail program; any ready-made script that uses a mail program will have to be significantly altered before it will work. If you're writing your own scripts and are planning to use TripodMail, keep this information in mind. The TripodMail.pm module also includes information about how it works and how to call the methods.

To start using one of the Tripod modules in a script, you'll first want to add this line of code to your script (for this example, we'll use the TripodCGI module): require TripodDate; This lets the Perl interpreter know that you want to have access to the functions in the module. Next, you can create an "object" that will let you access those functions. (If you know any object-oriented programming, this should sound familiar. Otherwise, just think of the object as a simple way to get access to those functions.) You create an object like this: $CGI = new TripodDate; The variable $CGI is now a TripodDate object. With it, you can use the functions in the TripodDate module. For example, you can use the currentDate() function, which returns today's date, like this: $todays_date = $CGI->currentDate();

This would assign the date to the $todays_date variable.

Limitations of Tripod's CGI

There are some important limitations to consider when running CGI scripts on Tripod. Certain Perl commands have been disabled for security reasons. This is to prevent people from performing such malicious acts as reading your private directories. People doing normal Web-site programming very rarely use most of these commands, but there are a few more common commands that you might want to know about. These are:
system
exec
fork
chown
chmod
sleep
unlink
kill
eval
All commands involving sockets

We've also limited how many system resources are available to each script. For example, a script can only use up to one second of CPU time before it is deemed to be causing problems and is terminated. This ensures that users don't accidentally -- or intentionally -- write scripts that run endlessly and eat up all of the server's resources. It's unlikely that you'll run into system-resource constraints unless you're running a script which requires an exceptional amount of processing time or memory.


<--BackContinue-->




    Tripod: Home | Site Map | About Tripod | International | Tripod Help | Report Tripod Abuse | Members | Angelfire Members

     » Lycos.com  © Copyright 2008, Lycos, Inc. Lycos is a registered trademark of Lycos, Inc. All Rights Reserved.
     About Lycos | Help | Jobs | Advertise

     Your use of this website constitutes acceptance of the Lycos Privacy Policy and Terms & Conditions