You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jann Linder <mo...@jann.com> on 2002/08/06 19:23:48 UTC

Question re: Session mgmt using mod_perl developer's cookbook (Sams)

HI ALL!

I bought this fantastic book and was reading chapter 12 section 3 and it had
a fantastic session stripping code for the uri so you needn't use cookies to
keep track of sessions, however, they suggest you append the session to each
and every link on your site in order to make this work.  (see the module
link below for more info)

http://www.modperlcookbook.org/code/ch12/Cookbook/URISessionManager.pm

My question is the following:

Can a mod_perl handler be inserted AFTER the content creation phase and
append this url automatically THROUGHOUT the html file on each OUTGOING
request so I do not have to worry about doing it myself?

(ie: if I have the following html code output:

<A HREF="/thisdir/thatfile.html">

It would automatically search this on the way out and change it to:

<A HREF="/SESSIONID/thisdir/thatfile.html">

A more interesting problem is FORMS.

Can I change:

<FORM ACTION="/thisdir/that.cgi" METHOD=etc...>

To 

<FORM ACTION="/SESSIONID/thisdir/that.cgi" METHOD=etc...>

Has anyone seen a solution?

PHP has an automatic solution in php4, I need it for perl!

I basically want to insert mod_perl handler in the equivalent outgoing phase
to the PerlTransHandler/PerlInitHandler.  I haven't seen a phase which
supports mauling files after they are created.


ps: if you HAVENT seen this book, it is mod_perl programmer's HEAVEN!  I
have been waiting for something like this since "Writing Apache Modules with
Perl and C"  (let's hope they update the cookbook when Modperl 2 is
finalized)

..Thanks to the authors who are probably members of this list.

Hlp?
TIA: Jann


Re: Question re: Session mgmt using mod_perl developer's cookbook (Sams)

Posted by Lyle Brooks <br...@deseret.com>.
Quoting Jann Linder (modperl@jann.com):
> HI ALL!
> 
> I bought this fantastic book and was reading chapter 12 section 3 and it had
> a fantastic session stripping code for the uri so you needn't use cookies to
> keep track of sessions, however, they suggest you append the session to each
> and every link on your site in order to make this work.  (see the module
> link below for more info)
> 
> http://www.modperlcookbook.org/code/ch12/Cookbook/URISessionManager.pm
> 
> My question is the following:
> 
> Can a mod_perl handler be inserted AFTER the content creation phase and
> append this url automatically THROUGHOUT the html file on each OUTGOING
> request so I do not have to worry about doing it myself?

Well, "after" the content creation phase (which only leaves the logging
and cleanup phases), the output has already left server on it's way to the
client.

If your content generators were Apache::Filter aware you could filter the
output of one mod_perl handler through a second mod_perl handler and have
it do the substitution.

But IIRC, the book mentions that you only have to do this URL munging on
absolute URLs.  If you use relative URLs in your HTML, you get the browser
to do the work for you.  And that is really cool!


Re: Question re: Session mgmt using mod_perl developer's cookbook (Sams)

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Jann Linder wrote:

> HI ALL!
> 
> I bought this fantastic book 


thanks - we're glad you are enjoying it.

> and was reading chapter 12 section 3 and it had
> a fantastic session stripping code for the uri so you needn't use cookies to
> keep track of sessions, however, they suggest you append the session to each
> and every link on your site in order to make this work.  (see the module
> link below for more info)
> 
> http://www.modperlcookbook.org/code/ch12/Cookbook/URISessionManager.pm


I wish we could take credit for the munged URI concept, but it's been 
around much longer than our book :)  more on this concept can be also 
found in the Eagle book and a few other CPAN modules, such as 
Apache::AuthCookieURL (which, despite the name, allows you to maintain 
state without cookies, IIRC)


> 
> My question is the following:
> 
> Can a mod_perl handler be inserted AFTER the content creation phase and
> append this url automatically THROUGHOUT the html file on each OUTGOING
> request so I do not have to worry about doing it myself?


no - once the content has been sent the content has been sent :)

what you can do is use some templating system or another to intercept 
flat files and manipulate them, or use a content filter (discussed in 
chapter 15) for chaining together content handlers.

however, you may not need either of these approaches (see below).


> 
> (ie: if I have the following html code output:
> 
> <A HREF="/thisdir/thatfile.html">
> 
> It would automatically search this on the way out and change it to:
> 
> <A HREF="/SESSIONID/thisdir/thatfile.html">
> 
> A more interesting problem is FORMS.
> 
> Can I change:
> 
> <FORM ACTION="/thisdir/that.cgi" METHOD=etc...>
> 
> To 
> 
> <FORM ACTION="/SESSIONID/thisdir/that.cgi" METHOD=etc...>
> 
> Has anyone seen a solution?


yes.  midway through the recipe we mention that modern browsers do 
this automatically for relative URIs (like the ones you show above). 
go ahead and install the handler and watch your relative URIs 
magically turn into URIs with the sessions embedded!  all you need to 
do is create an initial login handler that prepends a starting session 
and the browser will do the rest (or, insert a session by hand just to 
watch the magic happen)


> 
> PHP has an automatic solution in php4, I need it for perl!
> 
> I basically want to insert mod_perl handler in the equivalent outgoing phase
> to the PerlTransHandler/PerlInitHandler.  I haven't seen a phase which
> supports mauling files after they are created.


that's generally the kind of thing that Apache::Filter is used for if 
you have a handler that creates pages dynamically, but any handler can 
maniupate static files by opening a filehandle on $r->filename in the 
content generation phase.

is that what you mean?


> 
> 
> ps: if you HAVENT seen this book, it is mod_perl programmer's HEAVEN!  I
> have been waiting for something like this since "Writing Apache Modules with
> Perl and C" 


thanks.

> (let's hope they update the cookbook when Modperl 2 is
> finalized)


well... we'll see about that :)


> 
> ..Thanks to the authors who are probably members of this list.


sure

--Geoff



Re: Question re: Session mgmt using mod_perl developer's cookbook (Sams)

Posted by si...@siberian.org.
We do this with an HTML::Mason autohandler but that is a 
pretty implementation specific solution and doesn't solve 
the problem generically for mod_perl, works for us though 
:)

John-

On Tue, 06 Aug 2002 10:23:48 -0700
  Jann Linder <mo...@jann.com> wrote:
>HI ALL!
>
>I bought this fantastic book and was reading chapter 12 
>section 3 and it had
>a fantastic session stripping code for the uri so you 
>needn't use cookies to
>keep track of sessions, however, they suggest you append 
>the session to each
>and every link on your site in order to make this work. 
> (see the module
>link below for more info)
>
>http://www.modperlcookbook.org/code/ch12/Cookbook/URISessionManager.pm
>
>My question is the following:
>
>Can a mod_perl handler be inserted AFTER the content 
>creation phase and
>append this url automatically THROUGHOUT the html file on 
>each OUTGOING
>request so I do not have to worry about doing it myself?
>
>(ie: if I have the following html code output:
>
><A HREF="/thisdir/thatfile.html">
>
>It would automatically search this on the way out and 
>change it to:
>
><A HREF="/SESSIONID/thisdir/thatfile.html">
>
>A more interesting problem is FORMS.
>
>Can I change:
>
><FORM ACTION="/thisdir/that.cgi" METHOD=etc...>
>
>To 
>
><FORM ACTION="/SESSIONID/thisdir/that.cgi" METHOD=etc...>
>
>Has anyone seen a solution?
>
>PHP has an automatic solution in php4, I need it for 
>perl!
>
>I basically want to insert mod_perl handler in the 
>equivalent outgoing phase
>to the PerlTransHandler/PerlInitHandler.  I haven't seen 
>a phase which
>supports mauling files after they are created.
>
>
>ps: if you HAVENT seen this book, it is mod_perl 
>programmer's HEAVEN!  I
>have been waiting for something like this since "Writing 
>Apache Modules with
>Perl and C"  (let's hope they update the cookbook when 
>Modperl 2 is
>finalized)
>
>..Thanks to the authors who are probably members of this 
>list.
>
>Hlp?
>TIA: Jann
>