【发布时间】:2013-05-20 06:53:18
【问题描述】:
我一直试图在 Windows XP 上运行一个简单的 perl-cgi 脚本。这是一个带有提交按钮的简单 HTML 表单,单击提交按钮会显示一些文本(用户名)。但是单击 HTML 页面上的提交按钮,什么也没有发生。如果我用 url 打开浏览器,它工作正常。
HTML 表单:
<form id="form" name="form" method="post" action="C:/Server/Apache2/cgi-bin/hello.cgi" enctype="multipart/form-data">
<h1><center>User Login</center></h1>
<p><label><h4>Username</h4></label>
<input type="text" name="username" id="username" /></p>
<p><label><h4>Password</h4></label>
<input type="password" name="password" id="password" /></p>
<button type="submit">Sign-In</button><br><br>
CGI:
#!C:\perl\bin\perl.exe -wT
local ($buffer, @pairs, $pair, $name, $value, %FORM);
# Read in text
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}else {
$buffer = $ENV{'QUERY_STRING'};
}
# Split information into name/value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$user_name = $FORM{username};
print "Content-type:text/html\r\n\r\n";
print "<html>";
print "<head>";
print "<title>Hello - Second CGI Program</title>";
print "</head>";
print "<body>";
print "<h2>Hello $user_name - Second CGI Program</h2>";
print "</body>";
print "</html>";
1;
直接在浏览器中打开 CGI:
【问题讨论】:
-
apache 对错误日志说了什么?
-
@choroba:日志中没有错误。但我发现了另外一件事。如果我在我的 html 表单中使用 'action="/cgi-bin/hello.cgi"',因为我的 httpd.conf 有别名
ScriptAlias /cgi-bin/ "C:/Server/Apache2/cgi-bin/",通过单击提交按钮打开一个带有 urlC:\cgi-bin\hello.cgi的页面。但应该是C:/Server/Apache2/cgi-bin/hello.cgi