【发布时间】:2014-08-30 20:52:48
【问题描述】:
我有两个 cgi 脚本。 Login.cgi 和welcome.cgi 我想在这两个页面之间传递变量 这是我的两个页面
#!C:/Perl/bin/perl.exe -w
#login.cgi
use strict;
use warnings;
use CGI::Pretty qw(:all);
my $cgi = new CGI;
my $username = $cgi->param('username');
my $password = $cgi->param('password');
if ( ( $cgi->param('username') eq 'demo' ) && ( $cgi->param('password') eq 'demo' ) ) {
print $cgi->redirect("welcome.cgi");
}
else {
print header();
print start_html( -title => "Login" );
if ( $cgi->param('username') or $cgi->param('password') ) {
print center( font( { -color => 'red' }, "Invalid input" ) );
}
print generate_form();
print end_html();
}
sub generate_form {
return start_form,
h1("Please Login"),
p( "username", textfield('username') ),
p( "password", textfield('password') ), p(submit),
end_form;
}
另一个页面welcome.cgi
#!C:/Perl/bin/perl.exe -w
#welcome.cgi
use warnings;
use CGI::Pretty qw(:all);
use strict;
my $cgi=new CGI;
my $username;
print header();
print start_html("Welcome"),h1("Hello, $username");
print end_html();
如何将用户名变量传递给welcome.cgi?
【问题讨论】:
-
请将
my $cgi=new CGI替换为my $cgi = CGI->new。区别是微妙的,但是如果您养成像这样总是调用new的习惯,那么它可能会在将来的某个时候为您节省大量的调试时间。