You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jim Serio <ji...@rollercoaster.com> on 2000/06/12 18:27:22 UTC

POST & CGI weirdness

I've been running some mod_perl scripts for 6 months now 
without a hitch. All of my scripts use a custom module
that, among others, has a function to return an initialized
query object. Here's the function:

-----
# Initialize the CGI enviornment
sub init_cgi {

    # Reset and init the CGI handler
    CGI::_reset_globals();
    my $QUERY = new CGI;
    return($QUERY);

}
-----

I found about the CGI::_reset_globals from this list
and since using that I've had no problem with sticky
values across sessions.

Now I've begun work on a new module that has functions
used by Apache::Sandwich (actually, Apache::Sandwich
calls a wrapper script that calls print_header and
print_footer). print_header does some auth checking
to see if a use is logged in. These functions use
the init_cgi function from the other module. Up to
this point everythign is fine.

This handler is meant to be for HTML files but since
it's modularized I can call print_header/footer from 
within cgi-perl scripts. When called from a script that
attempts to send data via POST, my print_header function
hangs at the first instance that init_cgi is called.
GET works fine, but POST fails.

I read a message on here that said to try:

$query = new CGI qw(:standard);
_OR_
$query = new CGI '';

Upon changing my init_cgi function the script that POSTed
data works fine. BUT, now my older scripts that have
nothign to do with print_header/footer don't work. It seems
that maybe the handler has some effect on how you can
initialize the CGI object.

Now my init_cgi function is like this:

-----
# Initialize the CGI enviornment
sub init_cgi {

  my $FLAG = shift || 0;
  
  if ($FLAG == 1) {
    # Reset and init the CGI handler
    CGI::_reset_globals();
    my $QUERY = new CGI '';
    return($QUERY);
  }
  else {
    # Reset and init the CGI handler
    CGI::_reset_globals();
    my $QUERY = new CGI;
    return($QUERY);
  }
  
}
-----

The $FLAG=1 being from a script that will use POST.
Personally, I think this is pretty dirty and I'd like
to be able to solve the problem. Has anyone run into
this and have a cleaner workaround?

Jim