Hyper Dictionary

English Dictionary Computer Dictionary Video Dictionary Thesaurus Dream Dictionary Medical Dictionary


Search Dictionary:  

Meaning of CGI PROGRAM

 
Computing Dictionary
 
 Definition: 

(Often "CGI script") A program running on a web server to produce dynamic content, usually an html web page, in response to a user's request.

The common gateway interface specification defines the interface between the web server and such programs. The program can access any data that a normal application program can, however the facilities available to CGI programs are usually limited for security.

Although CGI programs can be compiled programs, they are more often written in a (semi) interpreted language such as perl, or as unix shell scripts, hence the name "CGI script".

Here is a trivial CGI script written in Perl. (It requires the "CGI" module available from cpan).

 #!/usr/bin/perl
 use CGI qw(:standard);
 print header, start_html,
   h1("CGI Test"),
   "Your IP address is: ", remote_host(),
   end_html;

When run it produces an http header and then a simple HTML page containing the ip address or hostname of the machine that generated the initial request. If run from a command prompt it outputs:

Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<HTML><HEAD><TITLE>Untitled Document</TITLE>

</HEAD><BODY><H1>CGI Test</H1>Your IP address is:

localhost</BODY></HTML>

The CGI program might be saved as the file "test.cgi" (or test.pl) in the appropriate directory on a web server, e.g. "/home/httpd/cgi-bin/".

A user could then type the appropriate url, e.g. http://www.acme.com/cgi-bin/test.cgi, into their web browser to get the program to run and a custom page produced for them.

Early web servers required all CGI programs to be installed in one directory called cgi-bin but it is much better to keep them with the HTML files to which they relate unless they are truly global to the site. All modern web servers make this easy to do.

 

 

COPYRIGHT © 2000-2013 HYPERDICTIONARY.COM HOME | ABOUT HYPERDICTIONARY