Common Gateway Interface

The common gateway interface is the middleware in which the web servers execute the user request from an external program. Such programs are called CGI programs. CGI provides the framework for the programs on interaction with HTTP(Hyper text transfer Protocol) server.

The user request through forms is passed on to the application program which processes the data and may give a confirmation message back. This process is called as Common Gateway Interface.



The Common Gateway Interface is the standard interface between the WWW consortium and the external program.

The CGI(Common Gateway Interface) is an executable program that is specified on the URL and passes a parameter to CGI program. The program is processed by HTTP Server and passes standard input to access environment variables. The output such as HTML elements is passed back to the HTTP server Thus it is the process of the CGI program.

When a user browses the web with a request using a URL to the server, the server parses the URL. The filename is searched which is kept in a pre-configured directory called CGI Directory and displays the file or error message back to the user.

The CGI program can be accessed by command line argument. From the server side invokes a program according to CGI specifications called CGI Script. CGI programs are written in C, PERL, Visual basic, shell script, C++, etc. The server receives user requests in the form of URLs and recognizes them as CGI scripts. The script is processed and passed back to the user output as a web client. The environment variables play a crucial role in writing the CGI program.

CGI applications

The interactive applications use CGI for collecting input from the user to the server. Let us discuss the applications as follows −


The Form contains CGI program and HTML. The form is a visual representation for collecting static data and accepting commands which are processed by the CGI program.

The HTML form consists of the button ‘submit’ and ‘action’ which push the URL to the server as a query string. After processing from the server it produces visual HTML pages for the user.

The form consists of Checkbox, text field, radio button, button, and selection list.


The Gateway scripts or program access database information in the form of SQL queries. In the database, the CGI program serves as a gateway to process the user query and display or retrieve virtual or dynamic information. Gateway programs can also interact with Archie, NNTP, or WAIS.

Virtual or dynamic document

The user request in the form of image, audio, text, or HTML to create a virtual document. The virtual document has a combination of gateways, forms, and graphics.

Consider an example: An user search for a painting on the web that is processed by the server which may state an error or display the image along with other image processing options like brightness, size or contrast back to the user. The CGI program can rewrite another program for modification of the image and display the resultant picture to the user.

Eg: Lycos browse user-requested documents and matches hypertext document results to the user. Another example is a dictionary in which a user search for an English word and returns an equivalent German word with the image to the user.

Other applications of the Common Gateway Interface are world maps, dictionaries, blogs, and coloring books.

CGI Features

  • The CGI is a simple interactive shell script or application.

  • CGI executes with a well-defined set of instructions.

  • CGI scripts are mostly written in Perl, C, etc. The applications can be written in any language like Java, Python, PERL, C++, C, etc.

  • HTML can also be used for interfaces where CGL is a technology.

  • CGI is easier than Java when advanced functions are performed.

  • CGI includes reusable pieces of code.

  • A basic and simple way for the user to request the server to get a response back.

CGI Advantages

The CGI is independent of languages on any platform as long as it conforms to specifications. The simple and easy-to-use written code. It is secure because CGI scripts run on the server. CGI is lightweight and easy to perform. Availability of tasks for CGI-based counters and CGI code for a simple task. The common gateway interface response is fast so results will be quick.

CGI Disadvantages

The CGI has disadvantages discussed below −

  • Each page incurs overhead to load each page program into memory.

  • During page loads, data cannot be cached in memory.

  • Existence of a huge code base mostly in Perl.

  • CGI takes a lot of time for processing.

  • Each request requires opening a new database connection making is costly and slow processed.

CGI security concerns

A user browser that implements CGI script may contain bugs causing potential threats. Due to this two more security concerns in CGI script arise,

Disclosure of information about the host intentionally or by mistake gives vulnerability that cybercriminals can break in.

The remote user can conceal to execute a command on CGI scripts.


The CGI(Common Gateway Interface) is a set of procedures according to interface specifications that propagates user requests to an application program or web server and gives a resultant response through the web interface to the user for web development. CGI contains several scripts and programs.

Updated on: 14-Apr-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started