develooper Front page | perl.macosx | Postings from February 2005

Looking for easy sessions using mod_perl

Thread Next
From:
Boysenberry Payne
Date:
February 18, 2005 10:43
Subject:
Looking for easy sessions using mod_perl
Message ID:
327ad691f41ba98dfb0010a82b9ea3a3@humaniteque.com
I'm moving from PHP to mod_perl.  What a jump...

Normally in php it's as simple as:
session_start();

Then depending on your settings the session is kept in a cookie
or in the url.

I've looked into Apache::Session a bit, also Session (which is a 
wrapper for Apache:Session.)
I set it up locally using my mysql database, but I'm getting now where 
fast.

Here is the code:
my $cookie = $r->header_in( 'Cookie' );
$r->print( "Content Type: text/plain\n\n" );
$cookie =~ s/SESSION_ID=(\w+)/$1/;

my %session;
eval {
   tie %session, 'Apache::Session::MySQL', $cookie,
     { DataSource => 'dbi:mysql:boysie_habitat2',
       UserName => 'boysie_human',
       Password => "h\@b!T",
       LockDataSource => 'dbi:mysql:boysie_habitat2',
       LockUserName => 'boysie_human',
       LockPassword => "h\@b!T",
     };
};

if( $@ ) {
   $r->print( "Couldn't tie session: $@" );
}

I get the following error:
null: Use of uninitialized value in substitution (s///) at 
/Users/WebRoot/perl/index.pl line 16.

I've tried printing out the cookie to see it and get the same error for 
anything I try to print it with.


It seems like it's being recorded ok in mysql.  I get the id fine, but 
the a_session column seems to be funky.
I'll copy an example below:
---------------------------------------

  e16d4be4a2f73b323184e8da1cef694d_session_id
---------------------------------------

You can't see it in the copy but there are a bunch of squares (I guess 
mac os x's new line characters.)

Any reason why this is so difficult to get working (besides my 
inexperience...)

Thanks,
Boysenberry


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About