3. The Common Gateway Interface
CGI (Common Gateway Interface) is the generic interface between the
server and server-side 'gateway' programs. CGI specifies how
data are sent to the gateway program, and how data can be returned by
the gateway program, through the server and back to the browser that
originally sent the data. The basic mechanisms are:
- Sending Data to the Gateway Program
- CGI (Common Gateway Interface) is the generic interface between the
server and these server-side 'gateway' programs. The CGI specifies how
data are sent to the gateway program (as environment variables or as
data read, by the gateway program, from standard input)
and what data are sent (in general, all the data sent by the client to the
server, plus extra environment variables describing the status of the
server).
- Returning Data to the Client
- To return data back to the client program (the user's web browsers)
the gateway program just writes data to it's regular (standard) output.
These data are sent back the the client, after some processing by the
server to ensure they have the correct message headers describing
the data and the state of the transaction. Of special note is the fact
that the gateway program must write to standard output,
before anything else, header messages explaining the MIME type of the data
being returned by the program -- this is the only way that the server can
know what type of data are being returned by the gateway program.
Thus the gateway program must, at the very list, print out a a two-
line header (the second of which must be a blank line):
Content-type: text/html The appropriate content-type header
A blank line separates the header from the data
data .... The data being returned