PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

CGI Include without Virtual()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CGI Include without Virtual()

    Does anyone have an idea how to adapt the php form include code?
    Code:
    $QSTRING = $_SERVER['QUERY_STRING']; 
            while (list ($header, $value) = each ($HTTP_GET_VARS)) 
            { 
            $QSTRING = $QSTRING.'&'.$header.'='.$value; 
            }
            virtual("/cgi-bin/search.cgi".'?'.$QSTRING);
    to something like:
    Code:
    putenv('REQUEST_METHOD=GET');
    putenv('QUERY_STRING=arg=value');
    passthru("/htdocs/www/cgi-bin/myscript.pl");
    So I can avoid using the virtual() function?

    The above is an exerpt from http://www.modwest.com/help/kb5-212.html, below is the full article. Thanks for any advice!

    -Matt

    I need the virtual() function and it is not available.


    When PHP runs as a cgi, that function is not available. However, you do not need it to accomplish your goals, which is having some other program executed at the same time as your php script, likely with output emitted as part of the html returned by the php script.

    In order to do this, you must first set in the PHP script whatever environmental variables your second script needs to use, such as REQUEST_METHOD and QUERY_STRING. Then, you execute the secondary script with a shell command with PHP.

    For example, suppose you want your PHP script to display the output of a perl script that you wanted to run like:

    virtual('/cgi-bin/myscript.pl?arg=value');

    Instead of the above in your PHP, you would do this:


    putenv('REQUEST_METHOD=GET');
    putenv('QUERY_STRING=arg=value');
    passthru("/htdocs/www/cgi-bin/myscript.pl");

    Notice that when using virtual() you refer to the script to be executed by a path that begins at the Apache DOCUMENT_ROOT, which is in most cases /htdocs/www on the physical filesystem. However, when exec'ing the script from a shell, you refer to it using the entire path starting at your home directory, which is "/".

    Also, myscript.pl must have executable permissions such as chmod 755.

    The only change you need to make to myscript.pl would be to get rid of any content type header that it output when called by virtual(), such as:

    print "Content-type: text/html\n\n";

    Any line such as the above is now no longer needed when you exec your script through a shell as described in this document and it should therefore be deleted or commented out, otherwise you will get that output printed in your PHP page.



  • #2
    It should just be something like the following:

    Code:
    $QSTRING = $_SERVER['QUERY_STRING'];
    putenv('REQUEST_METHOD=GET');
    putenv('QUERY_STRING='.$QSTRING);
     
    passthru("/htdocs/www/cgi-bin/search.cgi");
    The tricky part here is getting the correct path to your CGI. As mentioned above, this needs to be the filesystem path, and can vary from server to server.

    Of particular note, on a Windows server running Apache, your path may look something like this:

    Code:
    passthru("C:\\Progra~1\\Apache~1\\Apache2\\cgi-bin\\search.cgi");
    Note the use of "~1" for long folder names like "Program Files" and "Apache Group", as it appears that passthru() is unable to handle pathnames containing spaces.
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment


    • #3
      Ray thanks so much for your input, with your help I finally got Zoom CGI working with my host without having to adjust the php.ini file to enable virtual() -- woohoo!



      -Matt

      Comment

      Working...
      X