The Common Gateway Interface (CGI)
Defines what the common gateway interface is in relation to interactive web applications
CGI is a standard or set of rules that come into play whenever information entered on a browser needs to be processed by a program running on a server. CGI programs running on the server usually processes Internet forms. CGI is a way for the server to interact with the person using the browser. The data that goes into a CGI program has to comply with certain rules in order to be deciphered correctly by the program. The data sent as output from a CGI program also has to comply with the same set of rules. When a form is submitted, the CGI parameter CONTENT-TYPE contains "application/x-www-form-urlencoded" and the CONTENT-LENGTH CGI parameter contains the combined length of the names and values of all the form fields the user entered. Finally, the entries themselves would follow as a list of name-value pairs
The following example will show you how HTTP messages send form data to programs. Lets say that the user submits the following form by clicking on the 'GO' button
ScreenShot 2c: A Sample form at Submission Time
The browser will construct the following HTTP message to send to the server:
ScreenShot 2d: HTTP Request Message from Form at ScreenShot 2c
In the last line, why was 'Alita Fernandez' sent as the 'username'? Because the html form specified 'username' as the name of the field where 'Alita Fernandez' was entered. The radio button was given the name 'usergender' and the submit button was given the name 'submitbutton'. Look at the following excerpt from the html form. Each form field starts with a less than sign and the word 'input':
Please Enter Name: <input type = text name=username>
Please Select Gender: <input type=radio name=usergender value=M> Male
<input type=radio name=usergender value=F> Female
<input type=submit name=submitbutton value="GO">