安装Apache(1)
返回
CGIサンプルプログラム1
http://localhost/cgi-bin/printenv.pl
------------------------------------------------------------------------------
#!C:/Perl/bin/perl.exe
##
## printenv -- demo CGI program which just prints its environment
##
##print "Content-type: text/plain; charset=iso-8859-1\n\n"; ==>TEXT印刷はだめ!
print "Content-Type: text/html\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "-----------------------------------
";
# print "${var}=\"${val}\"\n";
print "${var}=\"${val}\"
";
}
出力
------------------------------------------------------------------------------
COMSPEC="C:\WINDOWS\system32\cmd.exe"
DOCUMENT_ROOT="C:/www/htdocs"
GATEWAY_INTERFACE="CGI/1.1"
HTTP_ACCEPT="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*"
HTTP_ACCEPT_ENCODING="gzip, deflate"
HTTP_ACCEPT_LANGUAGE="ja"
HTTP_CONNECTION="Keep-Alive"
HTTP_HOST="localhost"
HTTP_USER_AGENT="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
PATH="C:\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Ulead Systems\MPEG;C:\Program Files\Ulead Systems\Ulead DVD MovieWriter 3;C:\Program Files\MySQL\MySQL Server 5.0\bin"
PATHEXT=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"
QUERY_STRING=""
REMOTE_ADDR="127.0.0.1"
REMOTE_PORT="1922"
REQUEST_METHOD="GET"
REQUEST_URI="/cgi-bin/printenv.pl"
SCRIPT_FILENAME="C:/www/cgi-bin/printenv.pl"
SCRIPT_NAME="/cgi-bin/printenv.pl"
SERVER_ADDR="127.0.0.1"
SERVER_ADMIN="xxx@yahoo.co.jp"
SERVER_NAME="localhost"
SERVER_PORT="80"
SERVER_PROTOCOL="HTTP/1.1"
SERVER_SIGNATURE=""
SERVER_SOFTWARE="Apache/2.2.4 (Win32)"
SYSTEMROOT="C:\WINDOWS"
WINDIR="C:\WINDOWS"
CGIサンプルプログラム2
http://localhost/cgi-bin/Helloworld.pl
------------------------------------------------------------------------------
#!C:/Perl/bin/perl.exe
$url = "http://$ENV{SERVER_NAME}$ENV{URL}";
$ip = "$ENV{REMOTE_ADDR}";
print <
Hello World!
Hello World!
You have reached $url
Your IP Address is $ip
Have a nice day!