Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't include/execute a CGI file inside a PHP file
    primarykey
    data
    text
    <p>Using SSI, I can simply include this in my HTML file and the output of the CGI script is displayed on the page:</p> <pre><code>&lt;!--#include virtual="script.cgi"--&gt; </code></pre> <p>Now I'm trying to do the equivalent, but instead of a HTML file, it's inside a PHP file. I've been researching this all day and every solution is giving me the following problems. I'll list them each starting with the ones I thought should work as well as the obscure...</p> <hr> <p>1) <code>&lt;?php include("script.cgi"); ?&gt;</code></p> <p><strong>Result:</strong> No execution. This simply prints out the full content of the CGI file as if it was just a text file.</p> <hr> <p>2) <code>&lt;?php virtual("script.cgi"); ?&gt;</code></p> <p><strong>Result:</strong> <code>Fatal error: Call to undefined function virtual() in test.php on line #</code>.</p> <p>This bothers me as everything I read indicates that this is the proper way to do it. I'm no expert in PHP but how can <code>virtual</code> be an "undefined function"? It's <a href="http://php.net/manual/en/function.virtual.php" rel="nofollow">listed in the official PHP docs</a> as valid for PHP version 5.</p> <hr> <p>3) <code>&lt;?php exec("script.cgi"); ?&gt;</code></p> <p><strong>Result:</strong> Blank. Nothing.</p> <hr> <p>4)</p> <pre><code>&lt;?php $fd = fopen("script.cgi", "r"); fpassthru($fd); ?&gt; </code></pre> <p><strong>Result:</strong> No execution. This simply prints out the full content of the CGI file as if it was just a text file.</p> <hr> <p>5) <code>&lt;?php echo system("script.cgi"); ?&gt;</code></p> <p><strong>Result:</strong> Mixed. It executes but the "result" of the CGI script is printed twice and it's preceded by "Content-type: text/html". This I don't understand.</p> <p><code>Content-type: text/html resultresult</code></p> <p>And by removing the <code>echo</code>...</p> <p><code>&lt;?php system("script.cgi"); ?&gt;</code>, results in...</p> <p><code>Content-type: text/html result</code></p> <hr> <p>6) <code>&lt;?php print("/usr/bin/perl script.cgi"); ?&gt;</code></p> <p><strong>Result:</strong> No execution. It simply prints out what's contained after the print statement (<code>/usr/bin/perl script.cgi</code>). (I'm not surprised but somebody in a forum claimed this worked for them.)</p> <hr> <p>So what do I need to do in order to execute and include the results of the CGI file? This seems like it should be easy but I don't know what else to try.</p> <p>I'm on an Apache/Linux server (cPanel) with access to edit the <code>htaccess</code> file. It's running PHP version 5.2.17.</p> <p>And yes, when I pull up the CGI file in my browser, it executes and displays the result, so we know the server is configured to execute CGI files.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload