Pra*_*hur 0 forms perl cgi cgi-bin internal-server-error
我收到错误"内部服务器错误.服务器遇到内部错误或配置错误,无法完成您的请求."
我在html中提交表单并获取其值.
HTML代码(index.cgi)
#!c:/perl/bin/perl.exe
print "Content-type: text/html; charset=iso-8859-1\n\n";
print "<html>";
print "<body>";
print "<form name = 'login' method = 'get' action = '/cgi-bin/login.pl'> <input type = 'text' name = 'uid'><br /><input type = 'text' name = 'pass'><br /><input type = 'submit'>";
print "</body>";
print "</html>";
Run Code Online (Sandbox Code Playgroud)
用于获取数据的Perl代码(login.pl)
#!c:/perl/bin/perl.exe
use CGI::Carp qw(fatalsToBrowser);
my(%frmfields);
getdata(\%frmfields);
sub getdata {
my ($buffer) = "";
if (($ENV{'REQUEST_METHOD'} eq 'GET')) {
my (%hashref) = shift;
$buffer = $ENV{'QUERY_STRING'};
foreach (split(/&/,$buffer)) {
my ($key, $value) = split(/=/, $_);
$key = decodeURL($key);
$value= decodeURL($value);
$hashref{$key} = $value;
}
}
else{
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'})
}
}
sub decodeURL{
$_=shift;
tr/+/ /;
s/%(..)/pack('c', hex($1))/eg;
return($_);
}
Run Code Online (Sandbox Code Playgroud)
HTML页面打开正确,但是当我提交表单时,我收到内部服务器错误.
请帮忙.
Web服务器的错误日志说什么?
独立于它所说的,你必须自己停止解析表单数据.有模块的是,具体地CGI.pm.使用它,你可以这样做:
use CGI;
my $CGI = CGI->new();
my $uid = $CGI->param( 'uid' );
my $pass = $CGI->param( 'pass' );
# rest of your script
Run Code Online (Sandbox Code Playgroud)
更干净,更安全.