0% found this document useful (0 votes)
126 views3 pages

CGI (Common Gateway Interface)

CGI (Common Gateway Interface) provides middleware between web servers and external databases/information sources. It defines how programs interact with HTTP servers. When a user submits a form, the server passes the data to a CGI program which processes it and returns a response. CGI allows dynamic content generation and is commonly used to process forms, provide gateways to databases, and create virtual documents. Some examples of CGI applications include forms, gateways to access non-web data, and dynamically generating pages based on user input.

Uploaded by

Asmi Bhardwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views3 pages

CGI (Common Gateway Interface)

CGI (Common Gateway Interface) provides middleware between web servers and external databases/information sources. It defines how programs interact with HTTP servers. When a user submits a form, the server passes the data to a CGI program which processes it and returns a response. CGI allows dynamic content generation and is commonly used to process forms, provide gateways to databases, and create virtual documents. Some examples of CGI applications include forms, gateways to access non-web data, and dynamically generating pages based on user input.

Uploaded by

Asmi Bhardwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CGI( Common Gateway Interface)

30 March 2022 14:01


Asmi Bhardwaj
19BCY10168

The Common Gateway Interface (CGI) provides the middleware between WWW servers and external databases and information
sources. The World Wide Web Consortium (W3C) defined the Common Gateway Interface (CGI) and also defined how a
program interacts with a Hyper Text Transfer Protocol (HTTP) server. The Web server typically passes the form information to a
small application program that processes the data and may send back a confirmation message. This process or convention for
passing data back and forth between the server and the application is called the common gateway interface (CGI).

Features of CGI:

• It is a very well defined and supported standard.


• CGI scripts are generally written in either Perl, C, or maybe just a simple shell script.
• CGI is a technology that interfaces with HTML.
• CGI is the best method to create a counter because it is currently the quickest
• CGI standard is generally the most compatible with today’s browsers

Advantages of CGI:

• The advanced tasks are currently a lot easier to perform in CGI than in Java.
• It is always easier to use the code already written than to write your own.
• CGI specifies that the programs can be written in any language, and on any platform, as long as they conform to the
specification.
• CGI-based counters and CGI code to perform simple tasks are available in plenty.

Disadvantages of CGI:

• In Common Gateway Interface each page load incurs overhead by having to load the programs into memory.
• Generally, data cannot be easily cached in memory between page loads.
• There is a huge existing code base, much of it in Perl.
• CGI uses up a lot of processing time.

CGI (Common Gateway Interface) is a standard way of running programs from a Web server. Often, CGI programs are used to
generate pages dynamically or to perform some other action when someone fills out an HTML form and clicks the submit
button. AOL server provides full support for CGI v1.1.

Basically, CGI works like this:

A reader sends a URL that causes the AOL server to use CGI to run a program. The AOL server passes input from the reader to
the program and output from the program back to the reader. CGI acts as a "gateway" between the AOL server and the program
you write.

Here is a diagram of how a CGI program runs:

For example, suppose you have a form that lets people comment on your Web pages. You want the comments emailed to
you and you want to automatically generate a page and send it back to your reader.

The reader fills out your form and clicks the "Submit" button. The <FORM> tag in your page might look like this:
<FORM METHOD="POST" ACTION="/cgi-bin/myprog">

The METHOD controls how the information typed into the form is passed to your program. It can be "GET" or "POST" (see
page 106). The ACTION determines which program should be run .

New Section 1 Page 1


Other ways for a reader to run a program are by providing a direct link to the program without allowing the reader to
supply any variables through a form, or by using the <ISINDEX> tag .

When AOLserver gets a request for a URL that maps to a CGI directory or a CGI file extension (as defined in the
configuration file, see page 105), it starts a separate process and runs the program within that process. The AOLserver also
sets up a number of environment variable within that process. These environment variables include some standard CGI
variables (see page 108), and optionally any variables you define in the configuration file for this type of program.
The program runs. The program can be any type of executable program. For example, you can use C, C++, Perl, Unix shell
scripts, or Fortran.

In this example, the program takes the comments from the form as input and sends them to you as email. If the form
method is "GET", it gets the input from an environment variable. If the form method is "POST", it gets the input from
standard input. It also assembles a HTML page and sends it to standard output.

Any information the program passes to standard output is automatically sent to the AOLserver when the program finishes
running.
The server adds any header information needed to identify the output and sends it back to the reader's browser, which
displays the output.

CGI Applications

CGI turns the Web from a simple collection of static hypermedia documents into a whole new interactive medium, in
which users can ask questions and run applications. Let's take a look at some of the possible applications that can be
designed using CGI.

• Forms
One of the most prominent uses of CGI is in processing forms. Forms are a subset of HTML that allow the user to supply
information. The forms interface makes Web browsing an interactive process for the user and the provider. Figure 1.2
shows a simple form.

Figure 1.2: Simple form illustrating different widgets

As can be seen from the figure, a number of graphical widgets are available for form creation, such as radio buttons, text
fields, checkboxes, and selection lists. When the form is completed by the user, the Submit Order! button is used to send the
information to the server, which executes the program associated with the particular form to “decode” the data.

Generally, forms are used for two main purposes. At their simplest, forms can be used to collect information from the user.
But they can also be used in a more complex manner to provide back-and-forth interaction. For example, the user can be
presented with a form listing the various documents available on the server, as well as an option to search for particular
information within these documents. A CGI program can process this information and return document(s) that match the
user's selection criteria.

• Gateways
Web gateways are programs or scripts used to access information that is not directly readable by the client. For example,
say you have an Oracle database that contains baseball statistics for all the players on your company team and you would
like to provide this information on the Web. How would you do it? You certainly cannot point your client to the database

New Section 1 Page 2


like to provide this information on the Web. How would you do it? You certainly cannot point your client to the database
file (i.e., open the URL associated with the file) and expect to see any meaningful data.

CGI provides a solution to the problem in the form of a gateway. You can use a language such as oraperl . Gateways,
Databases, and Search/Index Utilities, for more information) or a DBI extension to Perl to form SQL queries to read the
information contained within the database. Once you have the information, you can format and send it to the client. In this
case, the CGI program serves as a gateway to the Oracle database, as shown in Figure 1.3.

Figure 1.3: A gateway to a database

Similarly, you can write gateway programs to any other Internet information service, including Archie, WAIS, and NNTP
(Usenet News)

• Virtual Documents
Virtual, or dynamic, document creation is at the heart of CGI. Virtual documents are created on the fly in response to a
user's information request. You can create virtual HTML, plain text, image, and even audio documents. A simple example
of a virtual document could be something as trivial as this:

Welcome to Asmi's WWW Server!


You are visiting from diamond.com. The load average on this machine is 1.25.
Happy navigating!

In this example, there are two pieces of dynamic information: the alphanumeric address (IP name) of the remote user and
the load average on the serving machine. This is a very simple example, indeed!

On the other hand, very complex virtual documents can be created by writing programs that use a combination of graphics
libraries, gateways, and forms. As a more sophisticated example, say you are the manager of an art gallery that specializes
in selling replicas of ancient Renaissance paintings and you are interested in presenting images of these masterpieces on the
Web. You start out by creating a form that asks for user information for the purpose of promotional mailings, presents a
search field for the user to enter the name of a painting, as well as a selection list containing popular paintings. Once the
user submits the form to the server, a program can email the user information to a certain address, or store it in a file. And
depending on the user's selection, either a message stating that the painting does not exist or an image of the painting can
be displayed along with some historical information located elsewhere on the Internet.

Along with the picture and history, another form with several image processing options to modify the brightness, contrast,
and/or size of the picture can be displayed. You can write another CGI program to modify the image properties on the fly
using certain graphics libraries, such as gd, sending the resultant picture to the client.

New Section 1 Page 3

You might also like