AM above was right though probably not helpful for you. There is no such method as retrieve in CGI::Session. The session and cookie handling are done by creating a new object. You can configure it many different ways but it should work out of the box with tmp files and an auto-named cookie following the examples directly.
# (mostly) From the tutorial link above- use strict; # Important! use warnings; # Ditto! my $session = CGI::Session->new() or die CGI::Session->errstr; Above line will first try to re-initialize an existing session by cons +ulting cookies and necessary QUERY_STRING parameters. If it fails wil +l create a brand new session with a unique ID, which is normally call +ed session ID, SID for short, and can be accessed through id() - obje +ct method. We didn't check for any session cookies above, did we? No, we didn't, +but CGI::Session did. It looked for a cookie called CGISESSID, and if + it found it tried to load existing session from server side storage +(file in our case). If cookie didn't exist it looked for a QUERY_STRI +NG parameter called CGISESSID. If all the attempts to recover session + ID failed, it created a new session.
I know you said you spent hours reading CPAN docs so you might have seen it already but that tutorial is pretty direct and you're not likely to get a better answer anywhere. Your username prompts the following jest-
s/(?<=Reading )[^.]+(?=.)/is fundamental/;I know how frustrating some of this can be at first. I've done the same hours of reading or 500 permutations on a theme based on an assumption. But stick with it. It gets more fun all the time. :)
Oh, all right. Just thinking about the days I wasted early on because I was just missing some simple piece... Here, you go, a minimal working example. You should be able to play with configuration and code order pretty easily from this-
use strict; use warnings; use CGI::Session; use CGI qw( h1 p ); use CGI::Carp "fatalsToBrowser"; my $session = CGI::Session->new or die CGI::Session->errstr; print $session->header(); if ( $session->param("visits") ) { print h1("Welcome back!"); print p( sprintf("You've been here %d time%s.", $session->param("visits"), $session->param("visits") == 1 ? "" : "s", ) ); } else { print h1("Welcome first time visitor"); } $session->param( visits => $session->param("visits") + 1 );
In reply to Re: accessing session variables across different pages
by Your Mother
in thread accessing session variables across different pages
by s/^Perl/pain/i
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |