我有兩個cgi腳本。 Login.cgi和welcome.cgi 我想 這兩個頁面之間。在此傳遞變量是兩頁,我有在cgi/perl中通過重定向傳遞變量
#!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?
請更換'我的$ CGI =用'我$ CGI = CGI-> new'新CGI'。這種差別是微妙的,但如果你養成了總是調用'new'的習慣,它將在未來某個時候爲你節省大量的調試時間。 –