3ISE517 Internet Application Programming - CGI

Authors Avatar

Coursework for:

Internet Application Programming






Introduction        3                

Basic HTTP Requests        5

Using the Common Gateway Interface        

        Basic Overview of the use of CGI        6

        Explanation of how CGI is used        7

References        9

Appendix A:

        Program listing of HTML Form        12

        Program listing of CGI Script        14        

Appendix B:

        Screenshots of validation performed by CGI Script        16

Appendix C:

        Additional Features         18


        Every time we request a web page on our browser, the browser would have created a connection with a web server, sent a request and received the required page before displaying it on our screens. A basic representation of such a request in shown in the diagram below:

[Reference: , 23/11/08]


        Generally pages requested by web browsers are static web pages which would be held in the web server’s local repository.  All the web server has to do is, locate the requested web page and return it to the browser. What one means by a static web page is that its content does not change until its owner modifies it.


        But some applications or scenarios require information not from pages that have been pre-written but from pages that are generated based on user input. For example, when searching for an article on the web, the results are generated based on the search words entered by the user. Such web pages are known to be generated dynamically. Being able to produce output based on what the user has produced, makes web servers much more interactive. In these situations, the server would actually have to process the information and generate a page to send back to the user based on request. Web servers achieve this by the use of the Common Gateway Interface.

        Before moving onto how dynamic pages are created, the following section explains how a static web page would be requested and retrieved from a server.

Basic HTTP Requests

        Every time a user requests a webpage by clicking on a link or simply typing it into the address bar, the web browser would break down the URL into three main components:

  • The protocol , eg: http, ftp, https
  • The server,         eg:
  • And the filename, eg: /file.html

        Every web server has an IP address and a domain name. Using the IP address, the web browser would connect to the server. After the connection is formed, following the HTTP protocol, the browser sends a GET request, asking to retrieve the webpage. The server would then process the request, locate the required page and return the result. The server sends back a HTTP response to the browser, containing the HTML code for the webpage. The web browser would then interpret the HTML tags and display the web page.

Using the Common Gateway Interface

        The Common Gateway Interface (CGI) is a protocol which defines the rules for transmitting information between a web server and an external program. According to webopedia.com, any program that is designed to accept and return data that conforms to the CGI specification can be classified as a CGI program. Using such programs, allow web servers to dynamically interact with the users. CGI scripts can be written in any programming languages, such as C, Perl, Java, etc.

Join now!

Basic Overview of the use of CGI:

Using the database example mentioned on the web page at hoohoo.nesa, how CGI is used will be explained:

        If a person wants to share his database with the world by connecting to the web, he will require a CGI program to transmit information between the web browser and the database engine. When a client requires some information from the database, his web browser sends request to the server. The database engine using CGI executes a CGI script which would then process the request and return the results to the web browser. ...

This is a preview of the whole essay