【发布时间】:2014-07-20 01:07:15
【问题描述】:
我有这个问题,我的会话在第一页之后无法加载。它确实会在创建后获取第一个页面会话。这是我的第一页:
index.cgi
use strict;
use warnings;
use CGI qw/:standard/;
use CGI::Session qw/-ip-match/;
use CGI;
use DBI;
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);
my $username;
my $password;
my $session;
my $sid;
my $cookie;
my $cgi = CGI->new();
my $submit = CGI->new();
my $a = CGI->new();
$username = $a->param('username');
$password = $a->param('password');
$session = new CGI::Session("driver:File", undef, {Directory=>'/tmp/session'});
$sid = $session->id();
$cookie = $cgi->cookie(CGISESSID => $session->id);
$session->param("username", $username);
$session->flush();
print $cgi->header( -cookie=>$cookie,-location=>'index2.cgi' );
第一页工作正常,它在它应该创建的目录中创建了 cookie。它还存储我想要的用户名。这是第一页的结果。
$D = {'_SESSION_ID' => '4244435418205139ea02fde065811aa1','_SESSION_ATIME' => 1401441306,'_SESSION_REMOTE_ADDR' => '127.0.0.1','用户名' => 'admin1','_SESSION_CTIME' => 1 ;;$D
之后,第二个页面应该加载 cookie 并在该页面中打印它们。但它不起作用。这是我的第二页:
更新
index2.cgi
use strict;
use warnings;
use CGI;
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use CGI::Session qw/-ip-match/;
my $sid;
my $cookie;
my $session;
my $q;
my $name;
my $username;
my $cgi = CGI->new();
$sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
$session = load CGI::Session(undef, $sid, {Directory=>'/tmp/session'});
$username = $session->param("username");
print $sid;
print $session->header();
第二页中的两个打印都没有返回任何内容。这意味着它不会从第一页加载。我怎样才能做到这一点?我的代码有什么问题吗?因为我是从 CGI::Session::Tutorial 学习的。有人可以帮帮我吗?
【问题讨论】:
-
举个例子,你可以看看3月份的这个答案:
How to access variable of other perl program in my perl program -
谢谢@miller 我会调查的