Forum Moderators: coopster

Message Too Old, No Replies

Parsing PHP within CGI

         

geckofuel

7:36 pm on Mar 13, 2003 (gmt 0)

10+ Year Member



In order to have php parsed within an html document, I made the following change to my .htaccess file.

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

However, I'd like to set my system up so that PHP was processed after a CGI document was finished being processed. Is this possible? Are there any good solutions?

Here's what I'm getting at: At this point, the cgi document merely posts the php code as a comment in the html that is served up. So, when you go to look at the source, you see the actual PHP code. I'd like for the php code to actually be processed (instead of showing up as comment).

Thanks for any help.
Gecko

nosanity

8:27 pm on Mar 13, 2003 (gmt 0)

10+ Year Member



Well, your problem here is you can't do that with apache as far as I know. If you generated PHP code, placed it in a file, then redirected to that file, it should work just fine... or move away from the cgi and go straight to PHP............

Better description of the problem:

for cgi to execute, you have to enable cgi for a file type... once you do this, you have to send what the content type is. But the output is still generated from the cgi script, however, this is where apache goes ok, lets just send this back to the browser. It has no clue that you are trying to generate php which is handled by a different module or cgi script...... your best bet if you NEED to do this is generate the code, write it to a file, then redirect to that new file.

noSanity

geckofuel

8:45 pm on Mar 13, 2003 (gmt 0)

10+ Year Member



Here's the deal:

I'm stuck with a UBB.classic discussion board which uses CGI. I'd like to be able to use a php random generator to place random donation values in a text box ($20, $30,$40, ...) up at the top of the board.

Here's the other deal:
I'd like to play around with Andreas' Getting rid of those query strings code to see if I can turn UBB's dynamic query strings into static URL's.

Any thoughts/help is appreciated.

andreasfriedrich

8:47 pm on Mar 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In Apache2 you can chain content handlers. In Apache1 this is a bit more tricky but possible as mod_gzip shows. It will however not be trivial to implement.

An easy way to include output of a script or program run via CGI is to use virtual() [php.net]. But this will not return the output of the CGI script to your PHP [php.net] script but directly to the server. To capture the output of a CGI script use output buffering and include the CGI resource or request it using the CURL functions or use backticks and a call to "wget -q -O /dev/stdout [aaron.com...]

Andreas

<added>I wrote that before Gecko´s explanation.</added>

nosanity

8:52 pm on Mar 13, 2003 (gmt 0)

10+ Year Member



Well in that case, even I want to know how! Come on... teach us!

noSanity