|
The Common Gateway Interface
(CGI) is a method of allowing a hyperlink to refer to a program
rather than a static web page. The easiest way to understand how
a CGI works is by contrast with an ordinary web page.
How does CGI work?
When
you use a browser to link to a URL, the browser requests that the host
named in the URL send the data specified by the rest of the URL. This
is normally just the contents of the file or directory specified by
the URL, encoded with the appropriate MIME type.
However,
if the URL points to a CGI, the computer on the far end runs the
program and sends its output to the client as though the output were
the contents of an HTML file. Depending on the URL, you might not
be able to tell that a CGI ever ran.
CGIs
are often used for processing submissions from HTML forms (collections
of fill-in fields, checkboxes, buttons, etc.). They can also generate
variable or customized content for a web page, ranging from visitor
counters to data based upon information supplied by the client browser.
How can I write a CGI program?
You
can write a CGI program in any programming language supported on the
server computer. You can find many tutorials on the web to help you
write a CGI program. In addition, a number of excellent packages have
been written that make it easier to program CGIs in Perl or C. To browse
a huge collection of resources about CGI, visit http://www.cgi-resources.com/.
|