adrive has asked for the wisdom of the Perl Monks concerning the following question:
test2.pl#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser/; use CGI::Session qw/-ip-match/; require "library.pl"; # instantiate a new CGI object my $cgi = new CGI; my $sessionid; my $session = new CGI::Session(); my $sessionid = $session->id(); print<<OUTPUT; <html> <body> <br><br> <form action="test2.pl" METHOD="POST"> <input type="hidden" name="sessionid" value="$sessionid"> <input type="submit" value="Generate Session"> </form> </body> </html> OUTPUT print xxx;
library.pl :#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser/; use CGI::Session qw/-ip-match/; require "library.pl"; # instantiate a new CGI object my $cgi = new CGI; my $sessionid = $cgi->param("sessionid"); my $msg = $cgi->param("message"); print<<OUTPUT; <html> <body> OUTPUT #display any added messages if any &DisplayMessage; # PERCULIAR - remove these and you won't see the "TESTING 1 2 3 SH +OULD SHOW" anymore! how to retain? # MARKING 1 # my $session = CGI::Session->load($sessionid); # MARKING 2 # $session->param("otherThings", "......."); # MARKING 3 #TO TEST .. THIS IS WHERE MESSAGE IS ADDED &AddMessage("TESTING 1 2 3 SHOULD SHOW\n\n"); print<<OUTPUT; <br><br> <form action="test2.pl" METHOD="POST"> <input type="hidden" name="sessionid" value="$sessionid"> <input type="submit" value="Refresh Page"> </form> </body> </html> OUTPUT print xxx;
#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser/; use CGI::Session qw/-ip-match/; # instantiate a new CGI object my $cgi = new CGI; my $sessionid = $cgi->param("sessionid"); sub AddMessage { my ($text)=@_; #open up existing session and add message my $session = CGI::Session->load($sessionid); $session->param("message", $text); print "added a new message.\n"; } sub DisplayMessage{ #prints the message out from previous saved session my $session = CGI::Session->load($sessionid); if($session->param("message")){ print $session->param("message"); }else{ print "no messages found.\n"; } } return 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: need serious help with CGI::Session
by almut (Canon) on Sep 26, 2007 at 10:07 UTC | |
|
Re: need serious help with CGI::Session
by adrive (Scribe) on Sep 27, 2007 at 01:28 UTC | |
|
Re: need serious help with CGI::Session
by Anonymous Monk on Dec 24, 2008 at 07:01 UTC |