开发者

Problem embedding a cgi within PHP using system

开发者 https://www.devze.com 2022-12-13 08:36 出处:网络
Hi I am using php system to embed a cgi-script like this <?php echo system(\'./cgi-bin/rebol-include.cgi\'); ?>

Hi I am using php system to embed a cgi-script like this

<?php echo system('./cgi-bin/rebol-include.cgi'); ?>

Problem is my cgi-script writes

print "content-type: text/html^/"

so that PHP will show up

"content-type: text/html"

above 开发者_如何学JAVAthe html page. This is an unwanted artefact, what's the optimal way to remove it knowing a whole html page is returned from the cgi to be embedded in php ?


System can be replaced with back ticks "`" and the result of the back tick can be inserted into a substring.

So

<?= substr(`./cgi-bin/rebol-include.cgi`, strlen('content-type: text/html^/')) ?>

This should give you everything after the "content-type".


Instead of printing out content within the script, return it as a string. Then echo will actually do its job. Also can parse whole content with strip_tags() or similiar if wanna get rid of HTML.


Have you tried using virtual() instead of system() ?

virtual() is an Apache-specific function which is similar to in mod_include. It performs an Apache sub-request. It is useful for including CGI scripts or .shtml files, or anything else that you would parse through Apache. Note that for a CGI script, the script must generate valid CGI headers. At the minimum that means it must generate a Content-Type header.

see http://php.net/manual/en/function.virtual.php

0

精彩评论

暂无评论...
验证码 换一张
取 消