Re: [Cgi-session-user] Sample program for CGI::Session not working as intended
Brought to you by:
sherzodr
From: Mark S. <ma...@su...> - 2006-12-25 02:11:38
|
Nagendran Saravanamoorthy wrote: > I want to use the CGI::Session for passing variables from one page to > another in a Perl/CGI application. I browsed through the archives and > found the sample code by Ron, which I have modified slightly. But I am > not getting the results I expected. Nagendran, Sorry for the delayed response. I think you need a call to $session->flush() at the end of the first program. This was intended to happen automatically, but especially since 4.x the "automatic" parts seems to have problems. We did update the documentation in the latest release to recommend to calling flush() in the Synopsis. I'm sorry this was frustrating for you-- I've been caught by a variation of the same thing as well. Mark > #!/usr/bin/perl -wT > > use strict; > use warnings; > use CGI; > use CGI::Session; > > # --------------- > my($id) = ''; > my($q) = CGI -> new(); > my $session; > > print "No Session ID passed in: \n"; > > $q -> param(CGI::Session -> name() => $id); > $session = CGI::Session -> new(); > $session->param( 'name', 'Steve' ); > > { > # This is program 1. > > print $session -> id(), '. New?: ', ($session -> is_new() ? 'Yes' : > 'No'), ". \n"; > $id = $session -> id(); > > } > > print "\n"; > print "Valid Session ID passed in: \n"; > > { > # This is program 2. > > $session = CGI::Session->load() or die CGI::Session->errstr; > > if ( $session->is_expired ) { > print "Your session expired, inevitably!"; > exit(0); > } > elsif ( $session->is_empty ) { > print "Initiating new session\n"; > $session = CGI::Session -> new(); > } > > print $session -> id(), '. New?: ', ($session -> is_new() ? 'Yes' : > 'No'), ". \n"; > $id = $session -> id(); > > } > > > > I get the following:- > > ########################################## > > As I have an active session when the execution enters program 2, I > expected the same cgi session id to be printed whereas I get > > No Session ID passed in: > 4c37844fedb49a0d8cf221968c382f60. New?: Yes. > > Valid Session ID passed in: > Initiating new session > 5a156b6ce4ba0f71e4bdb3814d4a3b23. New?: Yes. > > ########################################## > > Could someone please help in identifying the issue? > > Nag > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > ------------------------------------------------------------------------ > > _______________________________________________ > Cgi-session-user mailing list > Cgi...@li... > https://lists.sourceforge.net/lists/listinfo/cgi-session-user -- http://mark.stosberg.com/ |