473,806 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=${P ATH_TRANSLATED# #${DOCUMENT_ROO T}}
export SCRIPT_FILENAME =$PATH_TRANSLAT ED
/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 4808
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=${P ATH_TRANSLATED# #${DOCUMENT_ROO T}}
export SCRIPT_FILENAME =$PATH_TRANSLAT ED
/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_TRA NSLATED'}";
$template_txt = get_php($ENV{'P ATH_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_FI LENAME'} = $ENV{'PATH_TRAN SLATED'};
$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***@pricetra k.com> wrote in message
news:3f******** *************** @news.easynet.c o.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=${P ATH_TRANSLATED# #${DOCUMENT_ROO T}}
export SCRIPT_FILENAME =$PATH_TRANSLAT ED
/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
1844
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 #!/bin/perl -w ...... ...... $cmd = "import mypkg; do this; do that"; $string = `python -c \"$cmd\"`;
1
4997
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 webserver. If it is also possible to run a regular expression on this data that would also be great. It then outputs it in a nice format.
1
2797
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 correct order to create the database. What is the syntax for executing script files from Transact-SQL?
3
4990
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 to use the 'Shell()'-command . This didn't work: Either I get an "File not found" error, or I get no error at all, but the PERL script isn't executed anyway. The strange thing is that I managed to execute a .bat file for example. Why the hell...
0
467
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 = system "/usr/bin/suidperl", "-T", "/usr/local/bin/script.pl";
3
2411
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 think python is worse than perl
3
2174
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 PERL. So far, I have the javascript that does what I want to do, and it works fine as long as the the page was not generated by PERL. My problem is that when the javascript/html is generated by my PERL scripts the javascript never gets...
2
7005
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 to write a perl script on windows box which can trigger both, the batch file on B and the script on A Would you please help me...
1
1859
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 thing is, the script seems to be working fine when i run on the terminal (ie, perl <scriptname.cgi>), but i can't get the same output on the browser, when i give a sequence (input) on the text area of the html form. $seq variable seems to be storing...
0
9598
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10373
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.