![]() |
![]()
| ![]() |
![]()
NAME"CGI::Session::ExpireSessions" - Delete expired "CGI::Session"-type db-based and file-based sessions Synopsis#!/usr/bin/perl use strict; use warnings; use CGI::Session::ExpireSessions; use DBI; # ----------------------------------------------- my($dbh) = DBI -> connect ( 'dbi:mysql:aussi:127.0.0.1', 'root', 'pass', { AutoCommit => 1, PrintError => 0, RaiseError => 1, ShowErrorStatement => 1, } ); CGI::Session::ExpireSessions -> new(dbh => $dbh, verbose => 1) -> expire_db_sessions(); CGI::Session::ExpireSessions -> new(temp_dir => '/tmp', verbose => 1) -> expire_file_sessions(); CGI::Session::ExpireSessions -> new(verbose => 1) -> expire_sessions(); # Note: You are strongly urged to use method expire_sessions() (it requires CGI::Session V 4 or later), # since it does not eval the session data, and hence avoids the security issues of evaling a string # which comes from outside the program. See examples/expire-set.pl, which contains extensive comments. Description"CGI::Session::ExpireSessions" is a pure Perl module. It deletes "CGI::Session"-type sessions which have passed their use-by date. It works with "CGI::Session"-type sessions in a database or in disk files, but does not appear to work with "CGI::Session::PureSQL"-type sessions. The recommended way to use this module is via method expire_sessions(), which requires "CGI::Session" V 4 or later. Sessions can be expired under one of three conditions:
Sessions are deleted if any of these conditions is true. Sessions are deleted from the 'sessions' table in the database, or from the temp directory, depending on how you use "CGI::Session". DistributionsThis module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file. See http://savage.net.au/Perl-modules.html for details. See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro. SecurityFor file-based sessions, method expire_file_sessions() parses the contents of the file, using eval{}, in an attempt to determine the access and expiration times recorded within the file. So, if you are uneasy about the security implication of this (as you should be), don't use this method. Use method expire_sessions() instead. The latter is a much more sophisticated way of expiring sessions, but it does require "CGI::Session" V 4 or later. Constructor and initializationnew(...) returns a "CGI::Session::ExpireSessions" object. This is the class's contructor. Usage: CGI::Session::ExpireSessions -> new(). This method takes a set of parameters. Only some of these parameters are mandatory. For each parameter, call method new() as new(param_1 => value_1, param_2 => value_2, ...). Note: As of V 1.07 of this module, you may call method set() to set parameters after calling method new(). Not only that, but you may pass into all of the 3 methods expire_db_sessions(), expire_file_sessions() and expire_sessions() any of the parameters accepted by new(), since these 3 methods call set() if their caller provides parameters. Parameters which can be used with new(), set(), or "expire_*()":
The default value is 2 * 24 * 60 * 60, which is the number of seconds in 2 days. By default, then, sessions which were last accessed more than 2 days ago are expired. This parameter is optional.
Method: expire_db_sessions()Returns nothing. This method uses the dbh parameter passed to new() to delete database-type sessions. Method: expire_file_sessions()Returns nothing. This method uses the temp_dir parameter passed to new() to delete file-type sessions. Method: expire_sessions()Return value:
Returns the result of calling CGI::Session's method find(), which will be undef for some sort of failure, and 1 for success. This method handles both file-based and db-based sessions. Example codeSee the examples/ directory in the distro. There are 2 demo programs: expire-sessions.pl and expire-set.pl. Author"CGI::Session::ExpireSessions" was written by Ron Savage <ron@savage.net.au> in 2004. Home page: http://savage.net.au/index.html CopyrightAustralian copyright (c) 2004, Ron Savage. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html POD ERRORSHey! The above document had some coding errors, which are explained below:
|