Web programming

Units WEB1P and WEB2P

The Common Gateway Interface

The Common Gateway Interface (commonly known as CGI) is a standard for linking web servers with executable programs (or scripts). It specifies how the server passes information into the program, and how the program passes information back out to the server. The output of the program must be a document (and associated headers) that the web server can pass (via HTTP) to the user's browser.

CGI programs can be written in almost any programming language that runs on the web server computer. Perl is perhaps the most common one.

Text Box:  
Figure 1 - Architecture of a CGI application

Figure 1 shows the architecture of a CGI application. The client browser communicates with the web server via the HTTP protocol. The server communicates with the CGI program via the CGI protocol.

In brief, CGI works as follows:

  1. When a web server receives an HTTP request for a URL that maps on to a CGI program (how this is determined we will see in a future lesson), it runs the program.
  2. It passes certain information to the program via environment variables. This information includes what the request method was (GET, POST, etc.), the query string (any information that followed the "?" in the URL), and, where available, details of the remote host making the request and the remote user.
  3. The program runs, using the information passed to it. It outputs the HTTP header(s) followed by the document.
  4. The web server reads the output of the program and passes it back to the requesting browser as the response to the HTTP request.

For more details, see

 

Last updated by Prof Jim Briggs of the School of Computing at the University of Portsmouth

 
The web programming units include some material that was formerly part of the WPRMP, WECPP, WPSSM and WEMAM units.