I am trying to use sessions in a website I'm building and I installed the CGI::Sessions module and got it to work fine, however when using it with the MySQL driver it will not save the session to the database unless the session handle is created locally within the subroutine. I'm trying to make the session accessible by everything in my program..works fine with the file driver however.
FreeBSD 4.9, MySQL 12.22, Perl v5.8.3
Here is a test script to demonstrate what I'm talkin about.
#!/usr/bin/perl
$dbn = "DBI:mysql:***";
$dbu = "***";
$dbp = "***";
use CGI;
use DBI;
use CGI::Session;
my $cgi = new CGI;
$dbh = DBI->connect($dbn, $dbu, $dbp, {RaiseError=>1,AutoCommit=>1}) o
+r die ($DBI::errstr);
&initsession;
&addanothervalue;
print $cgi->header;
print "$sessionid<p> $session<p><p>";
sub addanothervalue {
# -> comment out this line (to get working)
$session->param('test',1);
}
sub initsession {
#$session = new CGI::Session("driver:file",undef,{Directory=>'temp
+'});
# -> add my to this line below (to get working)
$session = new CGI::Session("driver:MySQL",undef,{Handle=>$dbh});
$sessionid = $session->id;
$session->expire('+1h');
}
the way it is set right now, it doesn't work - it won't save the info to the database. however if you make the session handle local - it saves it to the database with a smile.
thanks for any help,
webg
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.