我是Perl的CGI的老兄,请帮帮我,请在我犯错误的地方纠正我。
这是代码。问题是,在验证密码并找到正确的密码后,它不会重定向到下一页,而是提供此消息:
Status: 302 Found
Location: http://localhost/cgi-bin/Main.cgi
#!C:\perl\bin\perl.exe
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use strict;
use DBI;
use strict;
use warnings;
my $q = new CGI;
print "Content-Type: text/html\n\n";
if ($q->param("Login")) {
my $Password = param('Password');
if (!$Password) {
print "Please Enter the Password";
} else {
my $dbh = DBI->connect(
"dbi:SQLite:DEVICE.db",
"", "",
{
RaiseError => 1,
AutoCommit => 1
}
);
my $sth = $dbh->prepare("select * from Settings where Password = ?");
$sth->execute($Password);
if (my $pass = $sth->fetchrow_hashref) {
print redirect(-url => 'http://localhost/cgi-bin/Main.cgi');
} else {
print "Invalid Password";
display_form();
}
$dbh->disconnect;
}
}
if (($q->param("submit"))) {
process_form();
} else {
display_form();
}
sub process_form {
if (validate_form()) {
}
}
sub validate_form {
my $User_Password = $q->param("Password");
my $error_message = "";
$error_message .= "Please enter the Password<br/>" if (!$User_Password);
if ($error_message) {
display_form($error_message, $User_Password);
return 0;
}
}
sub display_form {
my $error_message = shift;
print <<END_HTML;
<html>
<head><title>Form Validation</title></head>
<body>
<form method="post">
<input type="hidden" name="submit" value="Submit">
<TABLE align="center" bgcolor=#B0C4DE>
<TR>
<TD> Enter The Password And Click Login</TD>
</TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR>
<TD><b>PASSWORD</b> : <input type="password" name="Password" size="20" maxlength="15" /></TD>
</TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR>
<TD align="center" colspan="2">
<input type="submit" name="Login" value="Login">
<input type="reset" name="Cancel" value="Cancel">
</TD>
</TR>
</TABLE
</form>
</body>
</html>
END_HTML
}