Welcome to WebmasterWorld Guest from 54.159.190.106

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Embedding PHP within PERL

How to embed PHP code within a CGI-PERL script

   
2:57 pm on Oct 11, 2011 (gmt 0)



Facing a strange problem, not sure if anybody faced similar issue.
Earlier I had a static content website which comprised of html files. In some of the pages I was using embedded PHP codes, which was running fine.
Now I have changed the architecture from static to dynamic as below.

http://example.com/category/subcategory.html is internally redirecting to http://example.com/cgi-bin/display.pl?category=subcategory thanks to .htaccess

Problem is now my embedded PHP codes are not getting executed, and writing the PHP content in PERL is not a valid option here.

How can I execute my old PHP code snippets from within the PERL scripts over apache ?

Please help. Thanks in advance.
3:13 pm on Oct 11, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



If you're using Apache2 and you can modify the server configuration, you might be able to change php's mode of operation to a filter instead of a content module, that way, cgi-scripts could output php-code and it would be parsed and run by php.
3:59 pm on Oct 11, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



writing the PHP content in PERL is not a valid option here.


Can you pull out the PHP code as a file of it's own and run a system or exec on it? So if you have

<?php
echo 'Hello World';
?>

You'd put that in a file like hello.php and could do one of these in the perl script.

system('hello.php');
exec('hello.php');
$response = `hello.php`;
print $response;

If it's a remote php, just use a fully qualified URL. Another option, which shouldn't be necessary, is to cURL it.
5:50 pm on Nov 10, 2011 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



There's the PHP::Interpreter module on CPAN. It works great!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month