Hi,
I'm having a weird problem with mason and mod_perl.
I have the following configuration:
        Apache  1.3.9
        Mod_perl        1.21
        Mason   0.8 (with both available patches)


I have a page that place login information into a session (handled by Mason)
but in other pages I can't always get the information I put in the session.
If I reload the page enough, I finally get it.

I put some debug lines in the Mason handler and discovered that the session
id is always empty.  I tried giving it a value myself put the same problem
creeps up.  If I run Apache with only one process, it works whether or not
there's a session id.  It seems to be a problem related to the use of global
variables but I can't seem to track it down.

Any help would be appreciated.

David

PS:
Here are the relevant parts of my config files:

------------- httpd.conf -------------

PerlRequire /usr/local/apache/conf/session_handler.pl

<Location /prototype>
  SetHandler  perl-script
  PerlHandler HTML::Mason
  allow from all
</Location>

--------- session_handler.pl ---------

#!/usr/bin/perl
package HTML::Mason;

use HTML::Mason;
use strict;

{  package HTML::Mason::Commands;
   use vars qw(%session);
   use CGI::Cookie;
   use Apache::Session::File;
   use DBI;
}

my $parser = new HTML::Mason::Parser;
my $interp = new HTML::Mason::Interp (parser=>$parser,
                        comp_root=>'/export/home/web/prototype/',
data_dir=>'/export/home/web/prototype/mason_data/',
                                out_mode=>'batch');
my $ah = new HTML::Mason::ApacheHandler (interp=>$interp);

chown ( [getpwnam('nobody')]->[2], [getgrnam('nobody')]->[2],
        $interp->files_written );

sub handler
{
    my ($r) = @_;

    return -1 if $r->content_type &&
                        $r->content_type !~ m#^text/|application/x-javascript#io;

    my %cookies = parse CGI::Cookie($r->header_in('Cookie'));
    my %session;

    eval

      tie %session, 'Apache::Session::File',
        ( $cookies{'AF_SID'} ? $cookies{'AF_SID'}->value() : undef );
    };

    if ( $@ ) {
      # If the session is invalid, create a new session.
      if ( $@ =~ m#^Object does not exist in the data store# ) {
        tie %session, 'Apache::Session::File', undef;
        undef $cookies{'AF_SID'};
      }
    }
#    $session{_session_id}="fdsfsdfsdfsdfdsf";
    if ( !$cookies{'AF_SID'} ) {
      my $cookie = new CGI::Cookie(-name=>'AF_SID',
                -value=>$session{_session_id}, -path => '/prototype/',);
      $r->header_out('Set-Cookie', => $cookie);
    } else {
      print STDERR "******* COOKIE ******\n", $cookies{'AF_SID'}, "\n";
      print STDERR "******* _SESSION_ID ******\n", $session{_session_id},
"\n";
    }

    my $status = $ah->handle_request($r);

    untie %session;

    return $status;
}

1;

Reply via email to