Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: CGI::Session problems

by Speedy (Monk)
on Mar 06, 2002 at 03:55 UTC ( [id://149604]=note: print w/replies, xml ) Need Help??


in reply to CGI::Session problems

I haven't actually used CGI::Session, so I may be off-base here. But from reading the description, it appears that statements like:

$Session->param(-name=>'age', -value=>$age, -force=>1);
and
$Session->param(-name=>'name', -value=>$name, -force=>1);

won't do what you expect.

I'm basing this on the descriptiong of save_param($cgi) at the CPAN site:

This method is the opposite of load_param(). It saves all the parameters in your CGI environment to your Session's parameters. For example, you might want all the information that user supplied in a form in your website to be saved into the session object. Again, remember to pass CGI object as the first and the only argument. Example:

$Session->save_param($cgi);


So I think first you have to get your CGI.pm variables right. Rather than the "$Session" statements you were using, you could try:

print $cgi->hidden(-name=>'name', -value=>"$name");
print $cgi->hidden(-name=>'age', -value=>"$age", -force=>'1');

immediately before the end_form and submit statements. This saves the name and age variables (with the force='1' making the incremented age variable replace the old "sticky" parameter).

Then at the top of the script, which you will now be re-entering after executing the "submit" statement, but this time with the CGI parameters "right" and actually available to the script, put the

$Session->save_param($cgi);

statement. (If you don't get the CGI parameter variable saved, in this case as hidden variable, as you found they will be lost. I suspect the $Session statements didn't save them either.)

Often in this case you might go away, using the cookie value for reentry later. Or you can recall it as your code now works. But until the values are saved in the CGI.pm space, you apparently can't save them one at a time into the CGI::Session database.

Live in the moment.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-05-21 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found