You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Sam Carleton <sc...@activex-dev.com> on 2000/07/16 22:11:07 UTC

howto config apache to allow perl to filter php pages

I would like perl to process a php page before or after the php
interpreter get's it hands on the file.  I am trying to add a navbar to
the PHP code.  How would I go about doing that?

Sam

Re: howto config apache to allow perl to filter php pages

Posted by Rob Tanner <rt...@onlinemac.com>.
--On 07/22/00 15:56:18 -0400 Sam Carleton <sc...@activex-dev.com> wrote:

>
> I was reading the O'Reilly book "Writting Apache Modules in Perl and C"
> and discovered the navbar example.  I really like how Stein/MacEachern
> designed the navbar code.  Once the code was written, it read in a
> configuration file so that it would know the url/name of all items on
> the navbar.  This config file was passed to the navar code via variable
> in the apache directive.  I put the navbar code into the essi example
> (enhansted server side include) so that one would only need to the
> correct comment <!--#NAVBAR--> in the html file.
>

Okay, now I understand what you're after.  However, the way you want to do 
it isn't supported in Apache 1.x unless you want to do some convoluted 
saving of the page on disk first and then doing an internal redirect from 
within mod-perl.  Simply stated, in Apache 1.x you can have only one 
handler for the response phase.  That limitation won't go away until 2.x. 
One thing you might try is putting it in FIXUP phase.  I don't think that's 
really the right place for what is really a response phase modification of 
the page, but on the other hand, I don't know that it won't work either -- 
you'll simply have to experiment.  I'm assuming you want to add the navbar 
to all your pages, both those built dynamically with PHP and also static 
pages that are simply served by apache without PHP getting in the loop. 
If, however, all your pages (or at least all those you'd like to add ther 
navbar to) are PHP pages, why not simply add a PHP include tag.  Files read 
in via an include my contain PHP tags, and that way you could simply write 
the navbar code in PHP.  Mind you, I'm not trying to say you shouldn't 
under any circumstances try and mix mod-perl and PHP.  Rather, I am 
suggesting that if the hoops you have to jump through get too convoluted, 
maintenance will become a bear.

-- Rob



       _ _ _ _           _    _ _ _ _ _
      /\_\_\_\_\        /\_\ /\_\_\_\_\_\
     /\/_/_/_/_/       /\/_/ \/_/_/_/_/_/  QUIDQUID LATINE DICTUM SIT,
    /\/_/__\/_/ __    /\/_/    /\/_/          PROFUNDUM VIDITUR
   /\/_/_/_/_/ /\_\  /\/_/    /\/_/
  /\/_/ \/_/  /\/_/_/\/_/    /\/_/         (Whatever is said in Latin
  \/_/  \/_/  \/_/_/_/_/     \/_/              appears profound)

  Rob Tanner
  McMinnville, Oregon
  rtanner@onlinemac.com

Re: howto config apache to allow perl to filter php pages

Posted by Sam Carleton <sc...@activex-dev.com>.
Rob Tanner wrote:
> 
> --On 07/16/00 16:11:07 -0400 Sam Carleton <sc...@activex-dev.com> wrote:
> 
> > I would like perl to process a php page before or after the php
> > interpreter get's it hands on the file.  I am trying to add a navbar to
> > the PHP code.  How would I go about doing that?
> >
> > Sam
> 
> The simple answer is wait for Apache 2.x, but since that's just barely
> alpha now, that's a looong [sic] while away.
> 
> The issue in Apache 1.x is that you can use only one handler in any
> particular phase to process you're request.  Thus, php or mod_perl (or cgi,
> depending on how you meant to invoke perl).
> 
> But the real question is why?  I have never done a navbar on a page (most
> of my web work is server app development, not pages), si I may be making
> some wrong assumptions here.  If you are creating the page with a cgi or a
> mod-perl app, I would think you would be able to do the whole thing without
> ever using PHP.
> 
> But, if what you are really doing is displaying a page with server-side
> components, PHP is a much better chice by far than cgi or mod-perl.  What
> are you trying to do that php won't do for you?

I was reading the O'Reilly book "Writting Apache Modules in Perl and C"
and discovered the navbar example.  I really like how Stein/MacEachern
designed the navbar code.  Once the code was written, it read in a
configuration file so that it would know the url/name of all items on
the navbar.  This config file was passed to the navar code via variable
in the apache directive.  I put the navbar code into the essi example
(enhansted server side include) so that one would only need to the
correct comment <!--#NAVBAR--> in the html file.

I think this is a great idea.  If I could get the navbar/essi code to
parse the php page either before or after php processed the page, the
navbar would always be there.

The bottom line:  I would like to have some navigation code that is
totally seperate from everything so that I don't have to worry about
broken links and stuff like that.  I also want the ability to change the
look/feel of the navigation without affecting everything. 

sam

Re: howto config apache to allow perl to filter php pages

Posted by darren chamberlain <da...@boston.com>.
Aaron Johnson (solution@gina.net) said something to this effect:
> I was thinking about the same thing awhile back.  It was interesting to me that
> lots of neat applications are PHP based.  I would like to be able to take the
> processed PHP page and include it inside of my mod_perl page.  I was thinking
> there are several ways I could handle.  I can have a seperate directory that
> process the php files and just use the LWP::Simple to get the page as a
> processed string.  Then replace any content with =~ s/blah/cool/ inside of the
> mod_perl processed page.  I do this with some cgi programs that I use
> currently.  It works ok, but the overhead must be tremendous.  Anybody else done
> anything similar?

Why not use a subrequest?

Get your content, generate the URI. Call:

my $subr = $r->lookup_uri($uri);
$subr->run;

And your subrequest (be it a mod_perl page, PHP, cgi, or static HTML) get
executed in the place where you call $subr->run.

Apache itself does tons of subrequests. mod_autoindex, for example.

And, actually, using LWP::Simple isn't that much extra overhead, provided it
already loaded and all that. Although I'd use LWP::UserAgent, not LWP::Simple.

(darren)

-- 
"The bad reputation UNIX has gotten is totally undeserved, laid on by people
who don't understand, who have not gotten in there and tried anything."
    -- Jim Joyce, owner of Jim Joyce's UNIX Bookstore

Re: howto config apache to allow perl to filter php pages

Posted by Joshua Chamas <jo...@chamas.com>.
Aaron Johnson wrote:
> 
> I was thinking about the same thing awhile back.  It was interesting to me that
> lots of neat applications are PHP based.  I would like to be able to take the
> processed PHP page and include it inside of my mod_perl page.  I was thinking
> there are several ways I could handle.  I can have a seperate directory that
> process the php files and just use the LWP::Simple to get the page as a
> processed string.  Then replace any content with =~ s/blah/cool/ inside of the
> mod_perl processed page.  I do this with some cgi programs that I use
> currently.  It works ok, but the overhead must be tremendous.  Anybody else done
> anything similar?
> 

You know how there's $Response->Include('xyz.inc') in the modperl
Apache::ASP ? This file will be executed as an ASP script locally 
and the output included in the stream.  One could imagine letting 
this method auto-detect for the http:// prefix, and if it exists 
use LWP to call the URL and include the output that way.

I have also started work on a $Response->TrapInclude() method
which will return the output instead of sending it straight to 
the client HTML buffer, you could TrapInclude then to capture
the lwp-request automatically for post processing.

If LWP behavior is available, I wonder whether to turn its 
abilities on by default, or require some LWPInclude config
to be activated first?

Also, I wonder whether to allow Apache::ASP to compile LWP
input as an ASP script.  Since ASP scripts can execute arbitrary
code, this seems to me to increase the potential security
risks to a site.

--Joshua

_________________________________________________________________
Joshua Chamas			        Chamas Enterprises Inc.
NodeWorks >> free web link monitoring	Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

Re: howto config apache to allow perl to filter php pages

Posted by Aaron Johnson <so...@gina.net>.
I was thinking about the same thing awhile back.  It was interesting to me that
lots of neat applications are PHP based.  I would like to be able to take the
processed PHP page and include it inside of my mod_perl page.  I was thinking
there are several ways I could handle.  I can have a seperate directory that
process the php files and just use the LWP::Simple to get the page as a
processed string.  Then replace any content with =~ s/blah/cool/ inside of the
mod_perl processed page.  I do this with some cgi programs that I use
currently.  It works ok, but the overhead must be tremendous.  Anybody else done
anything similar?

Aaron Johnson

Page is called ez_archive.html, there is a lot more going on then this simple
post, but this is the crux of what I am saying.
code sample (Apache::ASP based):

<%  use LWP::Simple;
my $get_string;
foreach my $key (keys %{$Request->QueryString}) {
        $get_string .= $key;
        # this should be concated with a & in regular cases, but this cgi
program
        # only has one element connected by ':'
        # i.e. $get_string .= "&$key";
}


my $content = get("http://www.mydomain.com/cgi-bin/ezmlm-cgi?$get_string");

$content =~ s#cgi-bin/ezmlm-cgi#$Session->{Instance}/email/ez_archive.html#g;
$content =~ s#ezmlm-cgi#ez_archive.html#g;
print $content;

%>

Rob Tanner wrote:

> --On 07/16/00 16:11:07 -0400 Sam Carleton <sc...@activex-dev.com> wrote:
>
> > I would like perl to process a php page before or after the php
> > interpreter get's it hands on the file.  I am trying to add a navbar to
> > the PHP code.  How would I go about doing that?
> >
> > Sam
>
> The simple answer is wait for Apache 2.x, but since that's just barely
> alpha now, that's a looong [sic] while away.
>
> The issue in Apache 1.x is that you can use only one handler in any
> particular phase to process you're request.  Thus, php or mod_perl (or cgi,
> depending on how you meant to invoke perl).
>
> But the real question is why?  I have never done a navbar on a page (most
> of my web work is server app development, not pages), si I may be making
> some wrong assumptions here.  If you are creating the page with a cgi or a
> mod-perl app, I would think you would be able to do the whole thing without
> ever using PHP.
>
> But, if what you are really doing is displaying a page with server-side
> components, PHP is a much better chice by far than cgi or mod-perl.  What
> are you trying to do that php won't do for you?
>
> -- Rob
>
>        _ _ _ _           _    _ _ _ _ _
>       /\_\_\_\_\        /\_\ /\_\_\_\_\_\
>      /\/_/_/_/_/       /\/_/ \/_/_/_/_/_/  QUIDQUID LATINE DICTUM SIT,
>     /\/_/__\/_/ __    /\/_/    /\/_/          PROFUNDUM VIDITUR
>    /\/_/_/_/_/ /\_\  /\/_/    /\/_/
>   /\/_/ \/_/  /\/_/_/\/_/    /\/_/         (Whatever is said in Latin
>   \/_/  \/_/  \/_/_/_/_/     \/_/              appears profound)
>
>   Rob Tanner
>   McMinnville, Oregon
>   rtanner@onlinemac.com


Re: howto config apache to allow perl to filter php pages

Posted by Rob Tanner <rt...@onlinemac.com>.
--On 07/16/00 16:11:07 -0400 Sam Carleton <sc...@activex-dev.com> wrote:

> I would like perl to process a php page before or after the php
> interpreter get's it hands on the file.  I am trying to add a navbar to
> the PHP code.  How would I go about doing that?
>
> Sam

The simple answer is wait for Apache 2.x, but since that's just barely 
alpha now, that's a looong [sic] while away.

The issue in Apache 1.x is that you can use only one handler in any 
particular phase to process you're request.  Thus, php or mod_perl (or cgi, 
depending on how you meant to invoke perl).

But the real question is why?  I have never done a navbar on a page (most 
of my web work is server app development, not pages), si I may be making 
some wrong assumptions here.  If you are creating the page with a cgi or a 
mod-perl app, I would think you would be able to do the whole thing without 
ever using PHP.

But, if what you are really doing is displaying a page with server-side 
components, PHP is a much better chice by far than cgi or mod-perl.  What 
are you trying to do that php won't do for you?

-- Rob

       _ _ _ _           _    _ _ _ _ _
      /\_\_\_\_\        /\_\ /\_\_\_\_\_\
     /\/_/_/_/_/       /\/_/ \/_/_/_/_/_/  QUIDQUID LATINE DICTUM SIT,
    /\/_/__\/_/ __    /\/_/    /\/_/          PROFUNDUM VIDITUR
   /\/_/_/_/_/ /\_\  /\/_/    /\/_/
  /\/_/ \/_/  /\/_/_/\/_/    /\/_/         (Whatever is said in Latin
  \/_/  \/_/  \/_/_/_/_/     \/_/              appears profound)

  Rob Tanner
  McMinnville, Oregon
  rtanner@onlinemac.com