NAME

CGI::Session::File - CGI::Session driver for

SYNOPSIS

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

use CGI::Session::File;
use CGI;

my $cgi = new CGI;

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

my $session = new CGI::Session::File($c_sid, 
	{
		LockDirectory	=>'/tmp/locks', 
		Directory		=>'/tmp/sessions'
	});

# 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 fresh one
{
	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::File is the driver for the CGI::Session to store and retrieve the session data in and from the plain text files. 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:

Directory

path in the file system 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::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::File($c_sid, 
	{
		LockDirectory => '/tmp', 
		Directory	  => '/tmp'
	});

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