Forum Moderators: coopster
I am trying to include a Perl CGI script in the following manner :-
<?php virtual("/home/example/www/cgi-bin/perlscript.pl?param1=a¶m2=b");?>
When displaying the page, I get an error - "Fatal error: Call to undefined function: virtual()"
If I use include() instead of virtual I get this error: "failed to open stream: No such file or directory"
Running phpinfo gives me PHP version 4.3.4 and Virtual Directory Support: disabled.
I know very little about PHP and simply tweak scripts to work for me - so does the fact that Virtual Directory Support is disabled mean I can't use the virtual() function?
Is there any way of getting round this and including my CGI script?
Thanks.
Make sure you have PHP installed into Apache as a module and not as a CGI. The virtual() function is only available using PHP as a module on apache.
There are two ways that I have generally dealt with including CGI output into PHP scripts. First is to use file() or file_get_contents() and the URL.
$cgiOutput = file_get_contents('http://www.domain.com/cgi-bin/script.cgi?arg=val');
Secondly, in some cases, such as if you are using the CGI search script "HTdig" you can actually just exec() the script with the correct command line options.
I believe that the first method is probably one of the most common. All though it is possible do what you are trying to with the virtual() function, it has many side effects such as flushing the output buffer and the query string is handled a little differently.
Hope that helps!
- Travis
Make sure you have PHP installed into Apache as a module and not as a CGI
I have got this working by doing as you say and then simply echoing $cgiOutput - would this be the right way to do it?
Thanks again.
PHPINFO gives Server API as CGI, so I suppose this means PHP is installed as a CGI, right? I'm assuming that I can't change this because this is how my host has installed it. Or can I?
Basically no. You could ask you host to install them as an Apache module (assuming they are using apache). Bust mostlikely you are stuck with what you have.
I have got this working by doing as you say and then simply echoing $cgiOutput - would this be the right way to do it?
I think, in this case, its pretty much your only choice. I have used that method in several cases and it works well for me. Just make sure that if you are passing any user data to the query string in file_get_contents() that you don't allow malicious users to pass whatever they want in there and mess things up.