Including a CGI file with a PHP include

Including a CGI file with a PHP include

Posted by: cliffster
Posted on: 2005-12-21 16:04:00

Hey all,

Just trying to include a call to a CGI script with a PHP include on a static PHP page. Here is what I'm trying:

<?php
$path = $_SERVER['DOCUMENT_ROOT'];
include("$path/to/script/hello.cgi");
?>

I can hit that script, but the results are the content of the script that I'm trying to include:

#!/usr/bin/perl # hello.cgi - simple script to test if perl is working print "Content-type: text/htmlnn"; print "Hello World from hello.cgi"; exit;

Anyone know if there is something that I should adjust to get this to work?

cliffster

Re: Including a CGI file with a PHP include

Posted by: Atropos7
Posted on: 2005-12-21 20:26:00

In reply to:

Anyone know if there is something that I should adjust to get this to work?


Read the documentation:
"The include() statement includes and evaluates the specified file."

In order for a Perl script to generate output, it must be executed. You're not going to be able to do what you what using the include() statement.

If the Perl script is CGI, then you will need a web server that will execute a Perl interpreter. A web server does so by handling HTTP requests for URLs to the Perl script. Thus you will need an HTTP client library that will submit a request to a web server. And that is where CURL comes in.


cool Perl / MySQL / HTML+CSS

Re: Including a CGI file with a PHP include

Posted by: cliffster
Posted on: 2005-12-22 10:56:00

Brilliant, thanks!

This worked like a dream, and I appreciate the link to the Wiki. I didn't even know that existed :-)

Tags: php includecgi scripthey