You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Greg Oliver <gr...@endtoendtech.net> on 2003/12/02 22:04:42 UTC
CGI::Session
I have a script that uses CGI::Session to store a hash.. I cannot
figure out how to get the has data back from the session. The script
follows, as well as the stored session data.
SCRIPT:
#!c:\\perl\\bin\\perl.exe
use DBD::ODBC;
use DBI;
use CGI;
use CGI::Session;
$dsn = 'driver=Microsoft Access Driver (*.mdb);dbq=c:\\ustor.mdb';
$dbh = DBI->connect("dbi:ODBC:$dsn", '','') or die "$DBI::errstr\n";
$sth = $dbh->prepare("SELECT * from draws");
$sth->execute;
$data = $sth->fetchall_hashref("transaction");
$cgi = new CGI;
$sid = $cgi->cookie("CGISESSID") || undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
$session->param( "ARRAY", $data );
%vars = (
"greg" => "1_day",
"kam" => "2_day",
);
$session->clear( ["testentry"] );
$session->param( "DATA", \%vars );
$database = "c:\\ustor.mdb";
$cookie = $cgi->cookie(CGISESSID => $session->id);
print $cgi->header( -cookie=>$cookie );
print "<PRE>\n";
$array_ref = $session->param("DATA") || [];
$array = $session->param("ARRAY") || [];
#print @{$array}{1}{draw_date};
foreach $key ( keys %{$array_ref} ) {
print "@{$array_ref}{greg}\n";
print "$key\n";
}
print join "\n", %{$array_ref};
print join "\n", %{$array};
print "$cookie\n";
print $#results;
print join "\n", @results;
STORED DATA:
$D = {"_SESSION_ETIME" => undef,"_SESSION_ID" =>
"96d75e3bde92904036bd199ef53abc48","ARRAY" => {1 => {"draw_date" =>
"2003-11-13 00:00:00","draw_remaining" => 100000,"draw_requested" =>
10000,"sub" => 10,"submitted" => "2003-11-13 00:00:00","transaction" =>
1,"draw_paid" => 5000},2 => {"draw_date" => "2003-12-02
00:00:00","draw_remaining" => 75000,"draw_requested" => 15000,"sub" =>
25,"submitted" => "2003-12-02 00:00:00","transaction" => 2,"draw_paid"
=> 12000}},"_SESSION_REMOTE_ADDR" => "127.0.0.1","_SESSION_CTIME" =>
"1070398637","_SESSION_ATIME" => "1070398637","DATA" => {"kam" =>
"2_day","greg" => "1_day"},"_SESSION_EXPIRE_LIST" => {}}
Thanks for any help -
Greg Oliver
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html