473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Executing php from with a perl script

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
3 4791
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SS | last post by:
I am trying to execute some python commands within a perl script and running into problems. The following works: python -c "import mypkg;do this; do that" however when I try to do something like...
1
by: speedster | last post by:
Hi. I need some help converting some php to perl. $meminfo = shell_exec( "free -o" ); I need to execute "free-o" in shell and get the results. It grabs memory information about a linux...
1
by: Phil | last post by:
Hi, I have my create statments for tables, procedures, views, etc in individual Transact-SQL script files (.sql). I wnat to write another script file that executes these scripts in the...
3
by: PzYon | last post by:
Hey 2gether! I'm trying to execute a PERL script on the web server when the user presses a button in an ASP.NET Web Application using Visual Basic. The most obvious solution for me seemed to be...
0
by: Ian Warford | last post by:
Hi, I have a problem with a PL/PerlU function trying to execute an external perl script. The script is suid to a non-root user and I am executing it in the PL/PerlU function as so : $rc =...
3
by: Pankaj | last post by:
I am facing a very basic problem as any new bie would face. I know perl and now i want to use python In perl, it is very simple , just "perl scriptname.pl" will execute the script. But i...
3
by: Nathan Gilbert | last post by:
I am wanting to use javascript to select between different *.css files dependent on the user's browser. I am also wanting to generate the html document containing this javascript dynamically using...
2
by: sunilsn | last post by:
Hi, I am newbie to perl, I hope you guys will help me resolve the challenge I am facing. I have a unix shell script on one UNIX machine say A, and a batch file on windows machine say B. Now I want...
1
by: idorjee | last post by:
hi all, i've been trying to write a perl cgi script to generate an html output of the blast (program) and it's parsed results on the browser. following are some of the few lines from the script. the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.