in reply to Re^2: Form Data inaccessible after establishing session
in thread Form Data inaccessible after establishing session

Hmm, ok, not as revealing as I would have hoped because I made a mistake. Try this instead
#!/usr/bin/perl -- use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session ( '-ip_match' ); use Data::Dumper(); Main( @ARGV ); exit( 0 ); sub Dumper { scalar Data::Dumper->new( \@_ )->Indent(1)->Useqq(1)->Dum +p; } sub Main { my $cgi = CGI->new(); my @array = $cgi->param(); print $cgi->header, $cgi->start_html; print '<table border=1><tr><td valign=top><pre>', $cgi->escapeHTML( Dumper( $cgi ) ), '</pre></td>'; my $session = CGI::Session->new(undef, undef, {Directory=>'e:\tmp' +}); print '<td><pre>', $cgi->escapeHTML( Dumper( $cgi, $session ) ), '</pre></td></tr></table>'; print <<HTML_BLOCK; <form name='loginform' method='post' action='1.pl'> <input type='hidden' name='form' value='login'> <table> <tr> <td> UserName: </td> <td> <input type='text' name='username'> < +/td> </tr> <tr> <td> Password: </td> <td> <input type='password' name='password +'> </td> </tr> <tr> <td> Environment: </td> <td> <select size=1 name='environment'> <option value="env1">env1</option> <option value="env2">env2</option> </select> </td> </tr> <tr> <td colspan=2 style='text-align=center'> <input type='submit' name='submit' val +ue='Submit'> <input type='reset' name='reset' value +='Reset'> </td> </tr> </table> </form> HTML_BLOCK print $cgi->end_html; }

Replies are listed 'Best First'.
Re^4: Form Data inaccessible after establishing session
by SitrucHtims (Novice) on Apr 22, 2011 at 14:09 UTC

    First submit of the form with new diagnostic code

    $VAR1 = bless( {
      .parameters => 
        form,
        username,
        password,
        environment,
        submit
      ,
      use_tempfile => 1,
      .etab => 1,
      .charset => ISO-8859-1,
      .fieldnames => {},
      .elid => 1,
      param => {
        environment => 
          env1
        ,
        password => 
          
        ,
        submit => 
          Submit
        ,
        form => 
          login
        ,
        username => 
          
        
      },
      escape => 1,
      .header_printed => 1
    }, 'CGI' );
    
    $VAR1 = bless( {
      .parameters => 
        form,
        username,
        password,
        environment,
        submit
      ,
      use_tempfile => 1,
      .etab => 1,
      .charset => ISO-8859-1,
      .fieldnames => {},
      .elid => 1,
      param => {
        environment => 
          env1
        ,
        password => 
          
        ,
        submit => 
          Submit
        ,
        form => 
          login
        ,
        username => 
          
        
      },
      escape => 1,
      .header_printed => 1
    }, 'CGI' );
    $VAR2 = bless( {
      _STATUS => 3,
      _OBJECTS => {
        id => CGI::Session::ID::md5
      },
      _CLAIMED_ID => undef,
      _DATA => {
        _SESSION_ID => 6f7c79d011c1c9b3460ba6460abb912f,
        _SESSION_ATIME => 1303482012,
        _SESSION_REMOTE_ADDR => 172.30.5.83,
        _SESSION_CTIME => 1303482012
      },
      _QUERY => bless( {
        .parameters => [],
        use_tempfile => 1,
        .charset => ISO-8859-1,
        .cookies => undef,
        .fieldnames => {},
        param => {},
        escape => 1
      }, 'CGI' ),
      _DRIVER_ARGS => {
        Directory => e:\\tmp
      },
      _DSN => {
        serializer => default,
        id => md5,
        driver => file
      }
    }, 'CGI::Session' );
    

    Second submit of the form with new diagnostic code

    $VAR1 = bless( {
      .parameters => [],
      use_tempfile => 1,
      .etab => 1,
      .charset => ISO-8859-1,
      .fieldnames => {},
      .elid => 1,
      param => {},
      escape => 1,
      .header_printed => 1
    }, 'CGI' );
    
    $VAR1 = bless( {
      .parameters => [],
      use_tempfile => 1,
      .etab => 1,
      .charset => ISO-8859-1,
      .fieldnames => {},
      .elid => 1,
      param => {},
      escape => 1,
      .header_printed => 1
    }, 'CGI' );
    $VAR2 = bless( {
      _STATUS => 3,
      _OBJECTS => {
        id => CGI::Session::ID::md5
      },
      _CLAIMED_ID => undef,
      _DATA => {
        _SESSION_ID => 755e9ac11d5d32afee89ea6b62ee2b4d,
        _SESSION_ATIME => 1303482093,
        _SESSION_REMOTE_ADDR => 172.30.5.83,
        _SESSION_CTIME => 1303482093
      },
      _QUERY => bless( {
        .parameters => [],
        use_tempfile => 1,
        .charset => ISO-8859-1,
        .cookies => undef,
        .fieldnames => {},
        param => {},
        escape => 1
      }, 'CGI' ),
      _DRIVER_ARGS => {
        Directory => e:\\tmp
      },
      _DSN => {
        serializer => default,
        id => md5,
        driver => file
      }
    }, 'CGI::Session' );
    

    The results appear a little different between Chrome and IE. In Chorme, there also appears to be some invalid cookie data. It does not appear that the invalid cookie data is the cause of the problem, because IE experiences the same problem without the invalid cookie data.

    $VAR1 = bless( {
      .parameters => [],
      use_tempfile => 1,
      .etab => 1,
      .charset => ISO-8859-1,
      .fieldnames => {},
      .elid => 1,
      param => {},
      escape => 1,
      .header_printed => 1
    }, 'CGI' );
    
    $VAR1 = bless( {
      .parameters => [],
      use_tempfile => 1,
      .etab => 1,
      .charset => ISO-8859-1,
      .fieldnames => {},
      .elid => 1,
      param => {},
      escape => 1,
      .header_printed => 1
    }, 'CGI' );
    $VAR2 = bless( {
      _STATUS => 3,
      _OBJECTS => {
        id => CGI::Session::ID::md5
      },
      _CLAIMED_ID => undef,
      _DATA => {
        _SESSION_ID => 32b1f255a425972a9b483e492a9b10f5,
        _SESSION_ATIME => 1303481232,
        _SESSION_REMOTE_ADDR => 172.30.5.83,
        _SESSION_CTIME => 1303481232
      },
      _QUERY => bless( {
        .parameters => [],
        use_tempfile => 1,
        .charset => ISO-8859-1,
        .cookies => {
          LtpaToken => bless( {
            value => 
              AAECAzREQjE4M0NENERCMTlGRURDTj1DdXJ0aXMgU21pdGgvT1U9RGFsbGFzL089RGFsdGlsZSrdDDrPqcZFN7ltFscJ5kNiYnI5
            ,
            name => LtpaToken,
            path => /
          }, 'CGI::Cookie' )
        },
        .fieldnames => {},
        param => {},
        escape => 1
      }, 'CGI' ),
      _DRIVER_ARGS => {
        Directory => e:\\tmp
      },
      _DSN => {
        serializer => default,
        id => md5,
        driver => file
      }
    }, 'CGI::Session' );
    

        Thanks, if I get it figured out, I will post back the fix.

        Thanks for the help, I have now figured out how to get around the problem. I figured it out while testing with CGI::Simple. While using CGI::Simple did work, I found out that CGI.pm also works fine if you pass the CGI object into the creation of the CGI::Session object.

        Before

        my $session = CGI::Session->new(undef, undef, {Directory=>'e:\tmp'});

        After

        my $session = CGI::Session->new(undef, $cgi, {Directory=>'e:\tmp'});

        When using the new code, my form data is always available in my CGI object and my CGI::Session object.

        Thanks again! (Complete testing code below)

        use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session ( '-ip_match' ); my $cgi = CGI->new(); my @array = $cgi->param(); print "CGI Form Data-->", "@array ", $cgi->param("environment"), "<br> +"; print $cgi->Dump; my $session = CGI::Session->new(undef, $cgi, {Directory=>'e:\tmp'}); print $cgi->escapeHTML( Data::Dumper::Dumper( $cgi ) ), "<br><br><br>" +; print $cgi->escapeHTML( Data::Dumper::Dumper( $session ) ), "<br>"; print <<HTML_BLOCK; <body> <form name='loginform' method='post' action='1.pl'> <input type='hidden' name='form' value='login'> <table> <tr> <td> UserName: </td> <td> <input type='text' name='username'> < +/td> </tr> <tr> <td> Password: </td> <td> <input type='password' name='password +'> </td> </tr> <tr> <td> Environment: </td> <td> <select size=1 name='environment'> <option value="env1">env1</option> <option value="env2">env2</option> </select> </td> </tr> <tr> <td colspan=2 style='text-align=center'> <input type='submit' name='submit' val +ue='Submit'> <input type='reset' name='reset' value +='Reset'> </td> </tr> </table> </form> </body> HTML_BLOCK