NAME

CGI::Session::DB_File - Driver for CGI::Session class

SYNOPSIS

use constant COOKIE => "TEST_SID";	# cookie to store the session id

use CGI::Session::DB_File;
use CGI;

my $cgi = new CGI;

# getting the 
my $c_sid = $cgi->cookie(COOKIE) || undef;

my $session = new CGI::Session::DB_File($c_sid, 
	{
		LockDirectory	=>'/tmp/locks', 
		FileName		=> '/tmp/sessions.db'
	});

# now let's create a sid cookie and send it to the client's browser.
# if it is an existing session, it will be the same as before,
# but if it's a new session, $session->id() will return a new session id.
{
	my $new_cookie = $cgi->cookie(-name=>COOKIE, -value=>$session->id);
	print $cgi->header(-cookie=>$new_cookie);
}

print $cgi->start_html("CGI::Session::File");

# assuming we already saved the users first name in the session
# when he visited it couple of days ago, we can greet him with
# his first name

print "Hello", $session->param("f_name"), ", how have you been?";

print $cgi->end_html();

DESCRIPTION

CGI::Session::DB_File is the driver for CGI::Session to store and retrieve the session data in and from the Berkeley DB 1.x. To be able to write your own drivers for the CGI::Session, please consult developer section of the manual.

Constructor requires two arguments, as all other CGI::Session drivers do. The first argument has to be session id to be initialized (or undef to tell the CGI::Session to create a new session id). The second argument has to be a reference to a hash with two following require key/value pairs:

Filename

path to a file where all the session data will be stored

LockDirectory

path in the file system where all the lock files for the sessions will be stored

CGI::Session::DB_File uses Data::Dumper to serialize the session data before storing it in the session file.

Example

# get the sessino id either from the SID cookie, or from
# the sid parameter in the URL
my $c_sid = $cgi->cookie("SID") || $cgi->param("sid") || undef;
my $session = new CGI::Session::DB_File($c_sid, 
	{
		LockDirectory=>'/tmp', 
		FileName=>'/tmp/sessions.db'
	});

For more extensive examples of the CGI::Session usage, please refer to CGI::Session manual

AUTHOR

Sherzod B. Ruzmetov <sherzodr@cpan.org>

COPYRIGHT

This library is free software and can be redistributed under the same conditions as Perl itself.

SEE ALSO

CGI::Session, CGI::Session::File, CGI::Session::DB_File, CGI::Session::MySQL, Apache::Session