keegan has asked for the wisdom of the Perl Monks concerning the following question:

Hey perl people, i've been googling for this problem for almost a full day now and i'm stumped. I found similar problems here on perlmonks, but none of the solutions seem to help.

First off, let me explain what i'm trying to do:

- I have a php page which i've designed my layout, it includes a perl cgi page based off the URL request paramater 's' (for example, http://myurl.com?s=foo will include foo.cgi).
- I can get perl code to execute fine when including like this

THe problem i'm having is that when i have variables posted to the php page via the GET methos (as in, i use ?s=foo), the included CGI scripts are seeing it, and for some funky reason, my POST variables do not come through.

For example: i have a file called post.cgi:
$query = new CGI; print $query->header(); foreach($query->param()) { print $_ ; } print $ENV{'CONTENT_LENGTH'}; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); print $buffer; #just for testing purposes


If i post directly to the cgi file (aka my form is <form action="post.cgi" method="POST">), it works almost perfectly. I see all the items sent from the posting page from within the foreach, and i see the number 25 from the ENV variable output, however, i dont see anything being put into $buffer.

Now, if i post to the exact same cgi file, but include it in my php page (so my form is this: <form action="./?s=post.cgi" method="POST">), the only output is 's' and '25' for the ENV output.

WHen i first saw this, i thought maybe perl uses the same ENV variable for both POST and GET, and one will overwrite the other. THis doesn't seem to be the case, however, since there is something in that ENV variable i'm outputting.

Can anyone provide some insight as to why this is happening?

Replies are listed 'Best First'.
Re: GET overriding POST?
by wazoox (Prior) on Mar 16, 2006 at 16:22 UTC
    What's not clear to me is how you "include" the perl from the php. Could you post the relevant php lines too?
Re: GET overriding POST?
by dorward (Curate) on Mar 16, 2006 at 16:26 UTC

    I'm confused. Where exactly does the URL "./?s=post.cgi" point to? A Perl CGI script or a PHP script?

    If the latter, how does the PHP call the Perl CGI?

      THis is the php code i use to include the file exactly:
      if(isset($_GET['s'])) { $page = $_GET['s']; $folder = "scripts/"; $ext = ".cgi"; } virtual($folder . $page . $ext);
      Normally i use the include() function in php, but for some reason CGI gets interpreted as plain text, so i have to use virtual.

        virtual does an HTTP request. Since you can't specify which method to use, I bet it virtual always uses GET.

        include doesn't work since the included file is treated as a PHP scripts (causing a Perl script to be outputed unexecuted).

        I think passthru or system will do the trick. In any case, this is a PHP problem, and has nothing to do with Perl.

        Well, perhaps you'd better ask on php monks :) because it's obviously a PHP problem. The php include() is used only to include PHP code. It can't work with anything else. And the documentation for virtual() states that

        Warning
        The query string can be passed to the included file but $_GET is copied from the parent script and only $_SERVER['QUERY_STRING'] is filled with the passed query string. The query string may only be passed when using Apache 2. The requested file will not be listed in the Apache access log.

        So basically if you're using Apache 1.3, you're stuck.

Re: GET overriding POST?
by zer (Deacon) on Mar 16, 2006 at 16:25 UTC
    why dont you just use CGI.pm to get the data. It is already loaded. And you can determine get or post
Re: GET overriding POST?
by zer (Deacon) on Mar 16, 2006 at 16:31 UTC
    the @ARGV list can probably give you what you need. I used to use your method but found the cgi.pm quicker
Re: GET overriding POST?
by zentara (Cardinal) on Mar 17, 2006 at 11:46 UTC
    I don't dable in cgi very often, but it was my understanding that you use either get or post, and can't use both. If a get string is there, the post is ignored. I think typically it goes like this:
    if ($ENV{'REQUEST_METHOD'} eq "GET") { $form_data = $ENV{'QUERY_STRING'}; } else { $form_data = <STDIN>;
    So as soon as that query string is detected, the method is set to GET, and it will override the POST.

    I'm not really a human, but I play one on earth. flash japh
      No POST overrides GET and the GET is visible as urlparam() from CGI.pm anyway so you can use both.