Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Losing session value

by hippo (Bishop)
on Dec 13, 2017 at 16:59 UTC ( [id://1205452]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Losing session value
in thread Lossing session value

You are not checking for an empty value, you are setting one. And if you don't do that, you are setting it to undef which is just as bad. Here is what I think you should be doing:

my $got_file_name = $cgi->param( 'doc_upload' ); # Store file name to use later but only if it is defined. $session->param("doc_uploaded", $got_file_name) if $got_file_name; my $filename_uploaded = $session->param("doc_uploaded");

Replies are listed 'Best First'.
Re^4: Losing session value
by Anonymous Monk on Dec 13, 2017 at 17:34 UTC
    Still a mystery, it doesn't work, I can't get the value from the session!

      So, here's an SSCCE which works well.

      #!/usr/bin/perl use strict; use warnings; use CGI::Session; my $session = CGI::Session->new or die CGI::Session->errstr; my $cgi = $session->query; my $html = '<h1>Session test</h1>'; my $field = 'doc_upload'; # Initial value my $gfn = $session->param ($field); $html .= $gfn ? "<p>Initial value: $gfn</p>" : '<p>No iniital value</p +>'; # New value my $newgfn = $cgi->param ($field); $html .= $newgfn ? "<p>Supplied value: $newgfn</p>" : '<p>No supplied value</ +p>'; if ($newgfn) { $session->param ($field, $newgfn); $html .= '<p>Initial value overwritten with new value</p>'; } $html .= qq{<form method="post"><input type="text" name="$field"/> <input type="submit" value="Submit new value"/></form>}; print $session->header, $html; $session->flush;

      The HTML is minimalistic but serves the purpose. Run this CGI a few times to convince yourself that it is indeed storing new values but only when supplied. Then see how this differs from your script and amend yours accordingly. Good luck.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found