By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

Executing php from with a perl script

P: n/a
I know perl and can write the script. What I want to do is to be able to
grab a page, pass it to php if it has the php extension, get the
results(html) and then send it to the browser. Is it possible?

I saw this bit of code on a server that seems to execute php. Don't know
what it means, but it gave me the idea.

#!/bin/bash
export SCRIPT_NAME=${PATH_TRANSLATED##${DOCUMENT_ROOT}}
export SCRIPT_FILENAME=$PATH_TRANSLATED
/usr/bin/php

Right now I have a program that protects a members area. IT runs ssi and it
delivers all of the html docs, images and videos. I am sending my own
headers using nph, but I want to be able to do the same with php without
having to write the php code to go with my program.

Any ideas or thoughts would be greatly appreciated.

Thanks
John Michael
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
John Michael wrote:
I know perl and can write the script. What I want to do is to be able to
grab a page, pass it to php if it has the php extension, get the
results(html) and then send it to the browser. Is it possible?

I saw this bit of code on a server that seems to execute php. Don't know
what it means, but it gave me the idea.

#!/bin/bash
export SCRIPT_NAME=${PATH_TRANSLATED##${DOCUMENT_ROOT}}
export SCRIPT_FILENAME=$PATH_TRANSLATED
/usr/bin/php

Right now I have a program that protects a members area. IT runs ssi and it
delivers all of the html docs, images and videos. I am sending my own
headers using nph, but I want to be able to do the same with php without
having to write the php code to go with my program.

Any ideas or thoughts would be greatly appreciated.


I do this all the time....

open FILE,"/usr/bin/php page.php|";
while (<FILE>) {
...
}

.... but you will have to write out any environment variables that the
php page may require such as REQUEST_METHOD and QUERY_STRING. Handling
POST requests is more difficult though.

Are you running the perl script under a web server? If so then the
environment is probably mosly set for you anyway.

Jul 17 '05 #2

P: n/a
Thanks for the start. I created a small script to test it. It is being
called from the web.

#print "Content-type: text/html", "\n";
#print "Cache-control: no-cache, must-revalidate", "\n\n";
#print "$ENV{'PATH_TRANSLATED'}";
$template_txt = get_php($ENV{'PATH_TRANSLATED'});
print "$template_txt";
exit;
################################################## ##########################
#########
sub get_php {
my $template_name = shift;
my $temp_txt;
open (TI, "/usr/bin/php $template_name|");
$temp_txt= join('',<TI>);
close TI;
return $temp_txt;
}

The script is called through apaches add-handler and action directive and
does receive the correct path to the file I want. I had to comment out the
headers because php sent it's own headers. This is what I got before
commenting them out, so I know it was called.

X-Powered-By: PHP/4.2.2 Content-type: text/html

However, it then gave me my entire script back(the one above). I received
none of the php page I wanted.

After commenting out the headers, I just received my entire script back to
the browser and again none of the page.

Any ideas.
Do you think it may have something to do with permissions maybe.

Thanks
JOhn Michael


Jul 17 '05 #3

P: n/a
I got it.

$ENV{'SCRIPT_FILENAME'} = $ENV{'PATH_TRANSLATED'};
$output = `/usr/bin/php`;
print $output;
exit;

You have to change the SCRIPT_FILENAME env variable to the file you want to
parse.

Thanks
JM
"Kevin Thorpe" <ke***@pricetrak.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
John Michael wrote:
I know perl and can write the script. What I want to do is to be able to grab a page, pass it to php if it has the php extension, get the
results(html) and then send it to the browser. Is it possible?

I saw this bit of code on a server that seems to execute php. Don't know what it means, but it gave me the idea.

#!/bin/bash
export SCRIPT_NAME=${PATH_TRANSLATED##${DOCUMENT_ROOT}}
export SCRIPT_FILENAME=$PATH_TRANSLATED
/usr/bin/php

Right now I have a program that protects a members area. IT runs ssi and it delivers all of the html docs, images and videos. I am sending my own
headers using nph, but I want to be able to do the same with php without
having to write the php code to go with my program.

Any ideas or thoughts would be greatly appreciated.


I do this all the time....

open FILE,"/usr/bin/php page.php|";
while (<FILE>) {
...
}

... but you will have to write out any environment variables that the
php page may require such as REQUEST_METHOD and QUERY_STRING. Handling
POST requests is more difficult though.

Are you running the perl script under a web server? If so then the
environment is probably mosly set for you anyway.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.