Tell me about it. I was surprised to see how small amount of information out 
there for the Apache2/mod_perl users with mason. I had to bang my head against 
the wall several times before getting small things working. Pro's - are you 
listening? We need more docs with Apache2 integration. It's a whole new beast.

 ------------------------------
Apu Islam
( E Pluribus Unum)



----- Original Message ----
From: Aaron Hawryluk <[EMAIL PROTECTED]>
To: Apu islam <[EMAIL PROTECTED]>; mason-users@lists.sourceforge.net
Sent: Thursday, November 6, 2008 5:59:02 PM
Subject: Re: [Mason] Can't get session working

Thanks!

Had to install Fedora's libapreq2 and perl-libapreq2 through yum, and
then the code worked flawlessly. Ended up with this test case for
sessions and cookies:

% if($cookie_in){
<% Dumper($cookie_in) %>
<% $cookie_in->thaw %>
Session ID: <% $sessionID %>
% }
% else{
No cookie!
% }
<%init>
use Data::Dumper;
use CGI::Session;
use Apache2::Cookie;
my $jar = Apache2::Cookie::Jar->new($r) ;
my $cookie_in = $jar->cookies('sessionID') ;
my $session;
my $sessionID;
print "Session ID is ".$cookie_in->thaw." at INIT.<br />\n";
if (!$cookie_in) {
    print "No cookie!<br />\n";
       $session = CGI::Session->new() ;
       $sessionID = $session->id() ;
       my $out_cookie = Apache2::Cookie->new( $r, -name =>'sessionID',
                                               -value => $sessionID) ;
       $out_cookie->bake($r) ;
}
else{
    print "There is a cookie!<br />\n";
    $session = CGI::Session->new(undef,$cookie_in->thaw);
    $sessionID = $session->id();
}
</%init>

Thanks much for the help, Apu. Next time someone spends hours googling
"mason apache2 sessions cookies" maybe they'll stumble upon this
thread instead of the stuff I found, which was NOT as helpful.  ;-)

On Thu, Nov 6, 2008 at 3:53 PM, Apu islam <[EMAIL PROTECTED]> wrote:
> If you are using Apache2, make sure you add this line to your httpd.conf 
> (didn't work for me without it)
>
> LoadModule      apreq_module            modules/mod_apreq2.so
>
> Here is an example to use the CGI::Session with Apache2::Cookie module
>
> ---------------------------------------------
>
> <% Dumper($cookie_in) %>
> <% $cookie_in->thaw %>
>
>
> <%init>
> use Data::Dumper ;
> use CGI::Session ;
> my $session = CGI::Session->new() ;
> my $sessionID = $session->id() ;
> my $jar = Apache2::Cookie::Jar->new($r) ;
> my $cookie_in = $jar->cookies('testcookie') ;
>
> if (! $cookie_in) {
>        my $out_cookie = Apache2::Cookie->new( $r, -name =>'sessionID',
>                                                -value => $sessionID) ;
>        $out_cookie->bake($r) ;
> }
>
> </%init>
> -------------------------------------------------
>
> you probably want the session ID creation on <%once> instead of <%init>. 
> however, this is a simple test that worked for me for Apache2
> Cookie module's bake() will put the cookie on outgoing header, ( on the 
> request $r ) and thaw() will give you the value of that cookie from the 
> incoming header.
> I hope this helps.
>
>
>
>
>  ------------------------------
> Apu Islam
> ( E Pluribus Unum)
>
>
>
> ----- Original Message ----
> From: Aaron Hawryluk <[EMAIL PROTECTED]>
> To: mason-users@lists.sourceforge.net
> Sent: Thursday, November 6, 2008 2:49:35 PM
> Subject: [Mason] Can't get session working
>
> Hi all,
>
> I'm new to the list (and Mason - which by the way, is awesome). I have
> a couple of questions about session and cookie handling. I could seem
> to find any cookie-cutter recipes out there that worked on my setup
> (Apache2,mod_perl2,latest Mason) so I thought I'd ask here. I'm just
> trying to bash this together and haven't dealt with sessions or
> cookies in Mason before.
>
> In my httpd.conf:
>
> PerlModule HTML::Mason::ApacheHandler
> <LocationMatch "/madmin.*\.html$">
>  PerlSetVar MasonDeclineDirs 0
>  SetHandler perl-script
>  PerlHandler HTML::Mason::ApacheHandler
>  PerlAddVar MasonAllowGlobals $session %cookies $sid
> </LocationMatch>
>
> in my index.html:
>
> <%perl>
> my $cookie = $r->headers_in->{Cookie} || '';
> use CGI::Session;
> use CGI::Cookie;
> use Data::Dumper;
>
> our %cookies = fetch CGI::Cookie;
> our $sid = $cookies{'CGISESSID'} || undef;
> our $session = new CGI::Session('Driver: File', $sid, {Directory=>'/tmp'});
>
> if ( !$cookies{'CGISESSID'} ){
>  $cookie = new CGI::Cookie(-name => 'CGISESSID',
>                                          -value =>$session->id(),
>                                          -path => '/',);
>  $r->headers_out->add('Set-Cookie' => $cookie);
> }
> </%perl>
> <....bunch of html ..>
> %print "<pre>".Dumper($session)."</pre>\n";
> <...more html ...>
>
> When I output $session via Dumper I always get $VAR1=undef. Can anyone
> point me at what I'm doing wrong, or point me at a cookie-cutter
> recipe that works?
>
> --Aaron
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Mason-users mailing list
> Mason-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mason-users
>
>


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to