Common Gateway Interface (CGI) is a standard for running external programs from a World-Wide Web HTTP server.
CGI specifies how to pass arguments to the executing program as part of the HTTP request.
It also defines a set of environment variables.
Commonly, the program will generate some HTML pages which will be passed back to the browser but it can also request URL redirection.
CGI allows the returned HTML (or other document type) to depend in any arbitrary way on the request.
The CGI program can, for example, access information in a database and format the results as HTML.
A CGI program can be any program which can accept command line arguments.
Perl is a common choice for writing CGI scripts.
Some HTTP servers require CGI programs to reside in a special directory, often “/cgi-bin” but better servers provide ways to distinguish CGI programs so they can be kept in the same directories as the HTML files to which they are related.