There is a plethora of different ways to handle sessions in perl
driven websites. I'll throw in my 2 cents by describing how I've
always liked to do it. My solution assumes that your using an SQL
database for persistent data storage; but that obviously isn't a
requirement, there are a lot of ways to manage persistent data. I
also assume that your using mod_perl-2.
1) Use libapreq2's Apache2::Cookie to give the client a cookie such
as "SID=57de5d0d-8315-0410-9c71-f10f4dd80f37" where
57de5d0d-8315-0410-9c71-f10f4dd80f37 is a UUID generated by
libapreq2's APR::UUID module. Three cheers for libapreq2! :-)
Subsequently store the UUID into a database.
2) Check for a session cookie when a client connects to the site,
again using libapreq2's Apache2::Cookie. If a session cookie exists,
use a short and sweet SQL statement (via DBI of course) to fetch the
session data from the back-end database and then a subsequent
statement to store the fetched data in various variables for the rest
site's code to use.
3) Have a single subroutine named, for example, store_session_data
called with arguments such as store_session_data(UUID=>
"57de5d0d-8315-0410-9c71-f10f4dd80f37" username => "rutski89",
favorite_color => "blue", auto_login => "yes") which then does on the
fly construction of an SQL statement to insert the session data into
the database.
It's a step up from using CGI::Cookie in terms of the amount of work
you have to do, but it's not too hard to implement. Personally, I
enjoy the extra level of control over back-end storage.
Patrick R.
On Jun 6, 2006, at 4:48 PM, Matthew wrote:
It could be that I just don't understand completely the nature of
mod_perl, but here goes.
Reason I'm confused is because there exists CGI::Cookie for
handling cookies in MP2, but there's also the libapreq library "for
MP2". It seems to me that the apreq lib is more "MP2 Native" than
CGI would be. Am I wrong? Are they equally 'native' ?
With that in mind, I'm looking for some module, that I'm sure
exists, that can manage sessions. I found Apache::Session but I
couldn't tell if it was MP2 native. Is there something else I
should be using for sessions that is 'better' with MP2?
Thanks,
Matthew