Link to home
Start Free TrialLog in
Avatar of scottg
scottg

asked on

PHP code from a CGI script?

Has anyone been able to sucessfully generate PHP code from a CGI script
and have it processed by PHP before its given to the browser?

For example, I have PHP, Perl CGI scripts, Apache and a MySQL database all
working fine under Linux.  When I run a CGI script from a web browser, it
outputs some stuff including some PHP code.  But the result is not like
it would be from a normal PHP phtml document - I can see the PHP code
in the browser because its not processed by PHP as its outputed from
the perl script.  Any ideas?

### Print Header ###
printf "Content-type: text/html\n\n";
printf "<head><title>test</title></head>";
printf "<body>";

printf "
<?
echo \"testing from PHP\";
?>
";

printf "
</body>";

I actually see the <? echo... ?> in the HTML source from the browser.  
Why? I want it processed by PHP first where I should see
"testing from PHP" on the web page.  Note: This exact PHP code
works fine from a normal HTML doc such as test.html, but not
when its generated from a CGI script like this.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of jconde
jconde

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scottg
scottg

ASKER

Thanks for your reponse.

I do have "AddType application/x-httpd-php3 .html" in my httpd.conf and it works fine normally.  

>Can't you just use php for youre application?

Ya, I probably can, but I'm not smart enough(with PHP).  I can understand how it would work with the CGI, but not PHP alone.

Do you have any examples?  I essentially have a form that I want to allow the user to search through a MySql database.  Its simple enough, I just need a jump start with a short example.  Maybe straight CGI is better?  E-Mail me at scottg@niagara.com if you have any code or additional thoughts.

Thanks.