CGI::SessionM - Module provides sessions support inside CGI-scripts.
À MySQL database is required for propertly functioning (DBI::mysql driver).
Version 2.00 05.03.2007
#If your module SessionM.pm is located in another directory than @ISA array contains: #use lib 'path to your lib'; use CGI::SessionM 2.00; -- or -- # If your module SessionM.pm is located in another directory than @ISA array contains: unshift(@INC,"path to your lib"); require CGI::SessionM;
my $session = new CGI::SessionM( -content=>'user data string', -count=>5, # maximum count of unsuccessful # attempt of password entering! (0 - endless attempts) -forbidden=>10800, # blocking period after unsuccessful # login in seconds (3 hours by default) -time=>1200, # session life time, in seconds after last # access to a page (20 minutes by default) -db=>'database name', -login=>'database username', -password=>'database password', -host=>'database server', # is empty by default -table=>'tablename for working with sessions data' # "sessionm" by default );
First stage. Authorization
my ($err, @authdata) = $session->authorize($login, (<$password eq '********'>), $content); $login - autorizing user login. The expression (<$password eq '********'>) returns "true" if entered password is correct! $content - user data string. $err - value returned by function (return code/error). See the errors description in ERRORS chapter. @authdata - processed data. See details in DESCRIPTION chapter.
Second stage. Session validating.
my ($err, @authdata) = $session->validate($GUIDM); $GUIDM - GUIGM of session. This value passes from one page to another on the site. $err - value returned by function (return code/error). See the errors description in ERRORS chapter. @authdata - processed data. See details in DESCRIPTION chapter.
Third stage. Session cancelling.
my $err = $session->logout($GUIDM); $GUIDM - GUIGM of session. This value passes from one page to another on the site. $err - value returned by function (return code/error). See the errors description in ERRORS chapter.
Table creation in database for working with sessions.
my ($err, $tablename) = $session->create_table(); Be attentive! This function is relates to DDL queries class. $err - value returned by function (return code/error). See the errors description in ERRORS chapter. $tablename - name of table to create.
Userdata updating.
Getting of class property of $session object.
print $session->echo(<key>) <key> - one of the enumeration: maxcnt,timeout,timedie,content,guidm,login,dt,id,cnt,table
Getting error description.
$session->echoerr($err);
The function returns description of result's value of procedures in variable $err.
IP-address of database server can be used as server name, e.g. 127.0.0.1. For non-standard port just add ";port=1234" after server name (1234 is example of port number). So the complete string will be -host=>"127.0.0.1;port=1234"
Authorize method takes "true" (non-0) and "false" (0) values as second parameter. For "true" value session will be created without error generation. Elsewise session will be created with error #1. See the errors description in ERRORS chapter.
Most of methods return session data in such sequence:
identifier of record in table
session identifier
IP address
session lifetime
user login entered for authorization
count of attempts to eneter password
user data
You need to care for pass GUIDM value (result of authorize method) from one page to another. It can be cookies operating or keeping GUIDM in GET/POST queries.
my ($err,@authdata) = $session->authorize($login, $password eq 'sample' , join "||", qw/primer dannyh polzowatelja/);
my $guidm = $authdata[1] || '';
...
my ($err,@authdata) = $session->validate($guidm);
if ($err == 0) { print "Set-Cookie: guidm=$guidm;\n"; } else { if ($err == 1) { $error = session->echoerr($err)." (attempt $authdata[0] of $authdata[1])"; } elsif($err == 4) { $error = session->echoerr($err)." (service is not available till $authdata[0])"; } elsif($err == 6) { $error = session->echoerr($err)." \{$authdata[0]\}"; } else { $error = session->echoerr($err); } }
CREATE TABLE sessionm ( id INT(11) default NULL auto_increment, guidm char(39) default NULL, ip char(255) default NULL, dt INT(11) default NULL, login char(255) default NULL, cnt int(5) default NULL, content text default NULL, UNIQUE KEY (login), PRIMARY KEY (id))
0 OK (<DATA_ARRAY>) - Success. Methos returned array: <DATA_ARRAY>
1 PASSWORD INCORRECT (<Attemption>,<Permissible>) - Password is incorrect. Attemption <Attemption> of permissible <Permissible>.
2 LOGIN INCORRECT () - Login is incorrect
3 GUIDM INCORRECT () - Incorrect GUIDM
4 FORBIDDEN (<Time>) - Access denies until <Time>
5 SESSION LOST () - Lost connection.
6 SESSION EXPIRED (<GUIDM>) - Lifetime <GUIDM> is over.
7 UPDATE DONE () - Userdata is updated.
8 TABLE CREATED (<TableName>) - Table <TableName> created.
9 LOGOUT DONE () - User is cancelled session
The usual warnings if it cannot read or write the files involved.
2.00 Initial release
Thanks to Dmitry Klimov for technical translating.
Lepenkov Sergey (Serz Minus), minus@mail333.com
minus@mail333.com
Copyright (C) 1998-2007 Lepenkov Sergej (Serz Minus) minus@mail333.com
Copyright (C) 1998-2007 D&D Corporation. All Rights Reserved
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'À'. Assuming CP1252
To install CGI::SessionM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::SessionM
CPAN shell
perl -MCPAN -e shell install CGI::SessionM
For more information on module installation, please visit the detailed CPAN module installation guide.