CGI is the Common Gateway Interface and is the scheme to interface other programs and systems to the HTTP Web protocol, using the same data protocols as the HTTP clients and servers.
|
In this section, we will cover
-
passing information from the web page to the CGI script
-
processing information on the server and returning formatted web pages back to the web client
-
an example using Perl as the scripting language
-
brief descriptions of other CGI capabilities
|
References:
-
HTML and CGI Unleashed, John December and Mark GInsburg, chapters 19, 20 and 21, Sams.net Publishing.
-
CGI Programming on the World Wide Web, Gundavaram, O'Reilly & Associates.
-
The CGI Book, William Weinman, New Riders Publishing.
-
Web documents.
|
CGI is the Common Gateway Interface and is the scheme to interface other programs and systems to the HTTP Web protocol, using the same data protocols as the HTTP clients and servers.
|
In this section, we will cover
-
passing information from the web page to the CGI script
-
processing information on the server and returning formatted web pages back to the web client
-
an example using Perl as the scripting language
-
brief descriptions of other CGI capabilities
|
References:
-
HTML and CGI Unleashed, John December and Mark GInsburg, chapters 19, 20 and 21, Sams.net Publishing.
-
CGI Programming on the World Wide Web, Gundavaram, O'Reilly & Associates.
-
The CGI Book, William Weinman, New Riders Publishing.
-
Web documents.
|
Using the method "get" in a form to pass data, all the input that the user types is put in the QUERY_STRING variable:
|
<form method=get action="http://www.some.box/name.pl">
|
Type your first name <input name="First Name"><br>
|
Type your last name <input name="Last Name"><br>
|
<input type=submit value="submit">
|
</form>
|
If the user types "Winona" and "Ryder" as values, the QUERY_STRING environment variable would have the encoded value "First+Name=Winona&Last+Name=Ryder".
|
Here is a Perl program that would print that string on the web client's window (without regular html tags):
|
#!/usr/local/bin/perl
|
print "Content-type: text/html\n\n";
|
print "You typed \"$ENV{QUERY_STRING}\" in the input boxes\n";
|
Method=Get is NOT RECOMMENDED as input too long can be lost!
|
The web server also makes available information about the user and the server, including such things as what type of browser made the request.
|
A list of environment variables available to the CGI program:
|
GATEWAY_INTERFACE REMOTE_HOST
|
SERVER_NAME REMOTE_ADDR
|
SERVER_SOFTWARE AUTH_TYPE
|
SERVER_PROTOCOL REMOTE_USER
|
SERVER_PORT REMOTE_IDENT
|
REQUEST_METHOD CONTENT_TYPE
|
PATH_INFO CONTENT_LENGTH
|
PATH_TRANSLATED HTTP_FROM
|
SCRIPT_NAME HTTP_ACCEPT
|
DOCUMENT_ROOT HTTP_USER_AGENT (browser)
|
QUERY_STRING HTTP_REFERER
|