I'm currently in the process of writing a wrapper for a site using Apache::Session and mod_perl.  I was having great success using the following code to either validate a cookie which was already present or set a new cookie if necessary:
 
        my $r = Apache->request;
        my $cookie = $r->header_in('Cookie');
        my $cgi = new CGI;
 
        $cookie =~ s/SESSION_ID=(\w*)/$1/;
 
        # create the session from the cookie or create a new one
        my %session;
        tie %session, 'Apache::Session::File', $cookie, {
                Directory     => '/tmp/sessions',
        };
 
        my $session_cookie = "SESSION_ID=$session{_session_id};";
        $r->header_out("Set-Cookie" => $session_cookie);
 
Now...this works like a charm, passing the cookie and reading the session....as long as all of the pages are on the same level of the tree...i.e. :
 
 
However....as soon as you move to anything below that:
 
 
I receive the following error (from the error_log):
 
        "Died at /usr/local/lib/perl5/site_perl/5.8.0/Apache/Session/Generate/MD5.pm line 40"
 
By using Mozilla's cookie manager I see that the path attribute of the cookie set in the browser is changed from:
 
        "/perl/"
to:
   
        "/perl/cookies/"
 
...but I can't seem to figure out why Apache::Session isn't using the combination of the SESSION_ID and the directory stated in the tie() (/tmp/sessions) to retrieve the cookie...the SESSION_ID hasn't changed?
 
Thnx much!
 
~j
 

Reply via email to