4.4.4 Example of CGI programs
This section describes the sample CGI programs and their execution examples.
- Sample CGI programs
-
The following is an example of sample program source that can be used in Windows version. This program is written in the Perl language and the program name is test-cgi.pl:
#! c:\bin\perl.exe $argc=$#ARGV+1; print "Content-Type: text/plain\n"; print "\n"; print "argc is $argc. argv is \"@ARGV\".\n"; print "SERVER_SOFTWARE = $ENV{'SERVER_SOFTWARE'}\n"; print "SERVER_NAME = $ENV{'SERVER_NAME'}\n"; print "GATEWAY_INTERFACE = $ENV{'GATEWAY_INTERFACE'}\n"; print "SERVER_PROTOCOL = $ENV{'SERVER_PROTOCOL'}\n"; print "SERVER_PORT = $ENV{'SERVER_PORT'}\n"; print "REQUEST_METHOD = $ENV{'REQUEST_METHOD'}\n"; print "HTTP_ACCEPT = \"$ENV{'HTTP_ACCEPT'}\"\n"; print "PATH_INFO = \"$ENV{'PATH_INFO'}\"\n"; print "PATH_TRANSLATED = \"$ENV{'PATH_TRANSLATED'}\"\n"; print "SCRIPT_NAME = \"$ENV{'SCRIPT_NAME'}\"\n"; print "QUERY_STRING = \"$ENV{'QUERY_STRING'}\"\n"; print "REMOTE_HOST = $ENV{'REMOTE_HOST'}\n"; print "REMOTE_ADDR = $ENV{'REMOTE_ADDR'}\n"; print "REMOTE_USER = $ENV{'REMOTE_USER'}\n"; print "AUTH_TYPE = $ENV{'AUTH_TYPE'}\n"; print "CONTENT_TYPE = $ENV{'CONTENT_TYPE'}\n"; print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}\n";
- Executing CGI programs
-
Specify the following in the Web browser and invoke the sample CGI program:
http://www.example.com/cgi-bin/test-cgi.pl/ABC?X=1&Y=2
- Result of sample program execution
-