For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2005 > Looking for easy sessions using mod_perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Looking for easy sessions using mod_perl
Boysenberry Payne

2005-02-18, 3:56 pm

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=20
wrapper for Apache:Session.)
I set it up locally using my mysql database, but I'm getting now where=20=

fast.

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

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

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

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

I've tried printing out the cookie to see it and get the same error for=20=

anything I try to print it with.


It seems like it's being recorded ok in mysql. I get the id fine, but=20=

the a_session column seems to be funky.
I'll copy an example below:
---------------------------------------
=05=06=03=01
e16d4be4a2f73b323184e8da1cef694d=0B_sess
ion_id
---------------------------------------

You can't see it in the copy but there are a bunch of squares (I guess=20=

mac os x's new line characters.)

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

Thanks,
Boysenberry

Perrin Harkins

2005-02-18, 8:55 pm

On Fri, 2005-02-18 at 12:43 -0600, Boysenberry Payne wrote:
> Normally in php it's as simple as:
> session_start();


It's that easy with mod_perl too if you use Apache::SessionManager.
Save yourself some trouble and just use that.

http://search.cpan.org/search?query...nager&mode=dist

- Perrin

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com