http://www.perlmonks.org?node_id=495066


in reply to Just Another Question About Sessions And User Management

Here is a small example:

#!/usr/bin/perl -w -I. use strict; use CGI; use CGI::Cookie; use CGI::Carp qw/ fatalsToBrowser /; # TODO - Hide errors. use CGI::Session; # # New CGI object; used to get access to the cookie(s). # my $q = new CGI; # # Get a CGI::Session object - either completely new, or one previousl +y # associated with the given cookie. # my $session = CGI::Session->new( 'driver:File', $q->cookie('CGISESSID') || $q->param('CGISESSID') || +undef, { Directory => '/tmp' } ) or die ($CGI::Session::errstr); # # Identifier for this session. # my $sessionid = $session->id(); # # Retrieve "count" from it. # my $count = $session->param("count") || "1"; # # Update the count in the session # $session->param( "count", ($count+1) ); # # Print a sample page showing the visited count: # print "Set-Cookie: " . $q->cookie( -name => 'CGISESSID', -value => $sessionid, -expires => '+1d', -path => '/' ) . "\n"; print "Content-type: text/plain\n\n"; print "You've been here $count times before\n";
Steve
--