PHP's virtual() and exec() functions
On most servers, the easiest way to call a CGI script from a PHP page — which is also known as embedding the CGI script into the PHP page — is to use PHP's virtual() function, like this:
But some servers don't support PHP's virtual() function. In that case, you can use the exec() function instead. This requires some extra code that's usually best kept in a separate file, which you might name call_script.php, although the filename can actually be whatever you'd like. Download this file (and rename it to call_script.php) to get this extra code.
In order to make that PHP file call your particular CGI script, you'll need to edit it and adjust these two lines near the top, replacing "script.cgi" with the actual filename of your CGI script:
$cgi_script_local = "/cgi-bin/script.cgi";
Now just upload call_script.php to the root (the top level) of your website, then in your PHP page, add this line wherever you want the CGI script's output to appear:
Using URL variables with the exec/call_script method
If you need to pass URL variables (also known as query-string variables) to the CGI script, with the virtual() method, you can include them right within the function call, for example virtual("/cgi-bin/script.cgi?year=2010"). But with the exec/call_script method, you need to add the variables within the call_script.php file instead. Edit that file and find the following line, near the middle of the file:
Just before that line, add the following new line:
Now your call_script.php file will pass that variable to the CGI script.