Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: CGI Session not passing session info between pages

by poj (Abbot)
on Apr 01, 2018 at 14:14 UTC ( [id://1212103]=note: print w/replies, xml ) Need Help??


in reply to CGI Session not passing session info between pages

As bliako said, use $session->flush(). Here is minimal example

#!perl # login.pl use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI::Session; use DBI; my $dir = '/inetpub/wwwroot/data/'; my $dsn = $dir.'session_management.db'; my $session = CGI::Session->new("driver:sqlite", '', {DataSource=>$dsn}) or die (CGI::Session->errstr); # '' to create new session my $sid = $session->id(); $session->param("user_logged_in", 'true'); $session->flush; my $cgi = new CGI; print $session->header(); print $cgi->start_html("Session Test"); print $cgi->h4('Create New Session'), $cgi->pre("SID : $sid"), $cgi->a({href=>'page1.pl'},"Goto Page 1"), $cgi->end_html;
#!perl # page1.pl use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI::Session; use DBI; my $dir = '/inetpub/wwwroot/data/'; my $dsn = $dir.'session_management.db'; my $session = CGI::Session->new("driver:sqlite", undef , {DataSource=>$dsn}) or die (CGI::Session->errstr); my $sid = $session->id(); my $session_status = $session->param("user_logged_in"); my $text = " Session ID: $sid; Session status: $session_status"; my $cgi = new CGI; print $cgi->header(); print $cgi->start_html("Session Test"); print $cgi->h4('Check status'), $cgi->pre($text), $cgi->a({href=>'login.pl'},"Goto Login"), $cgi->end_html;
poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1212103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found