[Cgi-session-user] Sample program for CGI::Session not working as intended
Brought to you by:
sherzodr
From: Nagendran S. <sa...@gm...> - 2006-12-08 15:37:15
|
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. #!/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 |