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