The Common Gateway Interface (CGI) by Ahmed Hamdy Eissa

The Common Gateway Interface (CGI):

The Common Gateway Interface (CGI) is not a programming language.
It is a standardized set of conventions. The standardized set of conventions specifies how the external programs are to interface with the Web server. CGI provides a way for Web servers to run external programs and incorporate their output into the pages they serve.

CGI programs are called scripts.
CGI programs can be written in C, Perl, Visual Basic, AppleScript, or any other programming language.
CGI programs are external programs interface with the Web servers; browsers are not even a part of this loop.

The server invokes (runs) a script written in a scripting language such as Perl or VDs the same way as (a script written in C or Visual Basic and then compiled into binary executable).

A browser without going through a server first cannot view the output of a CGI script (Program).

User Input Data:
1) A Web user enter input data into a Form and Submit it (send it).
2) The browser sends the URL of the CGI you requested and the form's data to the Web server.
3) The Web server receives the URL of the CGI you requested, and all the form input data from the browser.
The URL and the input data are URL-encoded as a single query string (see below), and appended to the CGI's program's pathname.
4) The Web server invokes (runs) the CGI program, supply it with the input your browser sends. Every CGI script (program) must accept data from the server.
5) The CGI program processes the data and sends its output back to the Web server.
6) The Web server directs the output back to your browser.

Forms with More Than One Input Field:
1) The pairing of name and value is important when a form contains more than one input field.
2) The browser would establish a connection and send a GET request to the server.
3) All the form's input data is strung together in a query string, which is appended to the CGI program's relative URL following a question mark.
4) The browser send the resulting extended URL (encoded) to the server as part of an HTTP GET request.
Encoded means any spaces in the original input data are replaced by plus signs.
5) A question mark separates the query string from the program's name, and within the query string ampersands separate the name=value pairs from each other.
6) All CGI programs accomplish decoding the query string back into pairs the same way.

The Relationship between a Form and the CGI Program that processes the Form:
1) The HTML Form takes in the user input.
2) The HTML Form feeds the user input to the CGI program.
3) The Form's HTML elements specify the appearance of the displayed Web page.
4) Also, the Form's HTML elements specify the appearance of the data sent to the CGI program.
5) The CGI program must be designed to accept the particular name=value pairs from the form.
6) The Form must be designed to give the CGI program the named values it expects.

Ahmed Hamdy Eissa's E-mail Address

Go to top of page

Ahmed's Home Page