 |
Rethinking the Datacenter
Sponsored by HP
Today's datacenters need to increase utilization, get control over power and cooling costs, and align with business objectives. Download this eBook to learn about the challenges facing the data center in a world where digital information is growing at a torrid pace and costs are being held in check. Learn more. »
|
|
Putting the Green into IT
Sponsored by HP
Electricity use in data centers is skyrocketing, sending energy bills through the roof, creating environmental concerns and generating negative publicity. "Going Green" means looking to technologies like virtualization, energy-efficient chips and racks, and implementing policies that extend beyond the data center. Learn more. »
|
|
Managing the Modern Network
Sponsored by HP
In a global economy where information crosses the globe in an instant, and where Web-based applications power business, it's more important than ever to ensure your network is safe from threats and optimized to deliver the data your business needs. »
|
|
Evaluating Software as a Service for Your Business
Sponsored by Webroot
Is Software as a Service just hype, or is something really going on here? See if your company can benefit as SaaS tries to change the face of the enterprise.
»
|
|
Is Your Disaster Recovery Plan Good Enough?
Sponsored by HP
Preparing for a disaster is more often than not part of the storage planning process, and it is one of the most difficult tasks, since it includes local hardware and software, networking equipment, and a test plan. Learn how to get disaster recovery right. »
|
|
|
|
|
|
CGI: The Common Gateway Interface for Server-side Processing
|
The Common Gateway Interface, or CGI,
permits interactivity between a client and a host operating
system through the World Wide Web via the
Hyper Text Transfer Protocol (HTTP).
It's a standard for external gateway programs to interface
with information servers, such as HTTP or Web servers.
A plain
HTML document that the Web
server delivers is static, which means it doesn't change.
A CGI program, on the other hand, is executed in real-time,
so that it can output dynamic information - perhaps a weather
reading, or the latest results from a database query.
CGI allows someone visiting your Web site to run a program on
your machine that performs a specified task.
|
Gateways are programs which handle information requests and return
the appropriate document or generate a document on the fly.
Your server can serve information which is not in a form
readable by the client (e.g. an SQL database), and act as a
mediator between the two to produce something which clients can use.
Gateways can be used for a variety of purposes,
the most common being the handling of FORM requests for HTTP.
An
HTTP
server is often used
as a gateway to a legacy information system;
for example, an existing body
of documents or an existing database application.
The Common Gateway Interface is a convention between HTTP server
implementors about how to integrate such gateway scripts and programs.
Gateway programs, or scripts, are executable programs which can be run
by themselves.
They have been made
external programs in order to allow them to run under various
(possibly very different) information servers interchangably.
Gateways conforming to this specification can be written in any
language which produces an executable file. Some of the more popular
languages to use include:
C or C++,
Perl,
Python,
TCL,
shells,
and many others.
It doesn't matter what language the program is written in, as long
as you have the permission and resources to run it on your machine
and the program is written correctly.
Getting Started
Here is a simple example demonstrating the Common Gateway Interface.
This example uses the
Perl language
because of its portability and relative ease of use.
When we explain operating system commands we will generally speak
UNIX.
Note that UNIX is CaSe-sEnSiTiVe.
Some servers allow your CGI programs to be anywhere in your web
directories, so long as the file name ends in ".cgi". Others require
you to put them only in the "/cgi-bin" directory. Check with your
system administrator.
Now, create a file called Hello.cgi:
#!/usr/bin/perl
$t = "Hello World!";
print <<EOT;
Content-type: text/html
<Title> $t </Title>
<H1> $t </H1>
EOT
- The first line must contain the path to your Perl interpreter.
Use the command "which perl" to check this.
- Scalar variables names in Perl start with the "$" character.
"$t" contains some text to be used later.
- The print statement prints everything following until the "EOT".
Text printed to "standard output" goes to the server and thence to the
browser.
- The first line printed is an
HTTP header to tell the
browser that an HTML file is coming.
- HTTP header lines must always be separated by a blank line from actual
data.
- The data sent is a
valid
HTML
document.
The Perl interpreter replaces "$t" with "Hello World!".
Save the file and exit.
Change the attributes of the file to make it executable:
chmod +755 hello.cgi
Create a link to it like this:
<a href="Hello.cgi">Hello.cgi</a>
Click on
Hello.cgi,
and if all's well, the script should respond with "Hello World!"
- Forms
- We've seen how a CGI script can send information back to a browser,
but how do we send information to a CGI script? This can be
accomplished using what are referred to as forms. Forms allow for
user defined information to be passed along from a Web browser to
a CGI program for processing.
- Environment Variables
- Unlike form variables, environment variables are not user defined
but are server defined. These variables are passed along everytime
a CGI script is invoked.
- Imagemaps
- Imagemaps allow users to click on a particular spot in an image
to retrieve another HTML document or to run a specified script.
Input
Environment Variables
Headers from the Client
Processing
CGI and Perl
Tracking the User
Output
Location Headers
Other Headers
Examples
- The INPUT tag:
text entry for The URL-Minder.
This is the most important of the form elements;
with it you can allow the user to input text or
passwords and submit them to the server for CGI processing.
- The SELECT tag: Navigation Menus
for CGI or
JavaScript processing.
- The TEXTAREA tag: Comments Feedback
to let your visitors send their comments to an email distribution list.
Selena Sol's WebWare A monthly column for the cultural anthropologist and other liberal arts hackers gone Webmaster.
CGI-Capable Web Servers
ServerWatch is the ultimate guide to Internet servers and Web development tools, and has information about which Web servers are CGI-capable.
CGI Authoring Resources
If you can't find what you're looking for, the WDVL's CGI Authoring Resources page will get you up to speed in no time!
Introduction to Web Programming: CGI
Introduction to Web Programming is a four half-day course designed by Selena Sol.
Rate
this Page @ The CGI Resource Index
|