<World-Wide Web> (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).
use CGI qw(:standard);
print header, start_html,
"Your IP address is: ", remote_host(),
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:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
</HEAD><BODY><H1>CGI Test</H1>Your IP address is:
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.