Re: Executing a CGI inside a PHP page (Again?)
| From: | Jeff Wilhelm | Date: | Wed, 02 Aug 2000 18:46:23 +0000 |
| Subject: | Re: Executing a CGI inside a PHP page (Again?) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9783@lists.php.net to get a copy of this message | ||
The function:
class http
{
function http_fopen($host, $path)
{
$fp = fsockopen($host,80);
if (!$fp)
{
return false;
}
fputs($fp,"GET $path HTTP/1.0\r\n");
fputs($fp,"Host: $host\r\n\r\n");
while(trim(fgets($fp,1024)) != ""); //removes HTTP headers
return $fp;
}
}
The code:
$http = new http;
$fp =
$http->http_fopen(http://www.yoursite.com,"/the/cgi-bin/directory/news.cgi?a
ction=var1&var2=var2");
if (!$fp){
echo "Error accessing CGI.";
} else {
while (!feof($fp)) {
$buffer .= fgets($fp, 4096);
}
}
echo $buffer;
HTH,
Jeff