使用CGI::Session::Driver::mysql的Perl CGI::Session
我在使用CGI::Session在MySQL数据库中存储会话时遇到问题 这里是一个片段使用CGI::Session::Driver::mysql的Perl CGI::Session,perl,session,cgi,Perl,Session,Cgi,我在使用CGI::Session在MySQL数据库中存储会话时遇到问题 这里是一个片段 #!/usr/bin/perl use CGI; use CGI::Session; use CGI::Session::Driver::mysql; use DBI; use DBD::mysql; use Net::LDAPS; require '../include/include.pl'; $LDAP_SERVER = 'my.test.ldap.example.com'; $LDAP_SSL_
#!/usr/bin/perl
use CGI;
use CGI::Session;
use CGI::Session::Driver::mysql;
use DBI;
use DBD::mysql;
use Net::LDAPS;
require '../include/include.pl';
$LDAP_SERVER = 'my.test.ldap.example.com';
$LDAP_SSL_PORT = '636';
$LDAP_BASE = 'ou=users,dc=example,dc=com';
$ldap = Net::LDAPS->new($LDAP_SERVER, port=> $LDAP_SSL_PORT)
or die "Unable to create LDAP object because: $! \n";
$dbh = DBI->connect("DBI:mysql:host=$db_host;database=$db_name",$db_user,$db_pswd)
or die "Unable to connect to database: \"$DBI::errstr\" $! \n";
$q = CGI->new;
$usr = $q->param('usr') || undef;
$userDN = "uid=$usr,$LDAP_BASE";
if($usr) {
$pwd = $q->param('pwd');
$ldapMsg = $ldap->bind($userDN, password=>$pwd);
$result = $ldap->code;
if ($result == 0) {
$session = CGI::Session->new('driver:mysql', undef,
{ TableName=>'car_sessions',
IdColName=>'id',
DataColName=>'a_session',
Handle=>$dbh})
or die "Unable to create session because: $!";
$session->expire('+1h');
$session->param(-name=>'car_login', -value=>$usr);
$sess_cookie = $q->cookie(-name=>'CGISESSID', -value=>$session->id, -expires=>'+1h', -path=>'/hr_car/');
$login_cookie = $q->cookie(-name=>'car_login', -value=>$usr, -expires=>'+1h', -path=>'/hr_car/');
print $q->header(-cookie=>[$sess_cookie, $login_cookie], -location=>'manage.cgi');
}
LDAP绑定正确,cookies设置正确,但我的会话表中没有显示任何内容
我可能做错了什么???我相信问题出在我。在自动刷新发生之前,DBI句柄明显存在超出范围的问题,因此在设置完会话并将其删除后,调用
$session->flush
对于$dbh
和friends,您可以使用globals代替globals来缓解这个问题,Perl可能能够以正确的顺序清理它们,这是一个好主意
PS打开strict和warnings并声明所有这些变量。你的问题很可能是由打字错误引起的,你永远不会知道。我相信问题出在你身上。在自动刷新发生之前,DBI句柄明显存在超出范围的问题,因此在设置完会话并将其删除后,调用
$session->flush
对于$dbh
和friends,您可以使用globals代替globals来缓解这个问题,Perl可能能够以正确的顺序清理它们,这是一个好主意
PS打开strict和warnings并声明所有这些变量。你的问题可能同样容易由打字错误引起,你永远不会知道。好吧$会话->刷新();好的$会话->刷新();