.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "CGI::Session::ExpireSessions 3pm" .TH CGI::Session::ExpireSessions 3pm "2021-09-25" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" CGI::Session::ExpireSessions \- Expires CGI::Session db\-based and file\-based sessions .SH "Synopsis" .IX Header "Synopsis" .Vb 1 \& #!/usr/bin/env perl \& \& use strict; \& use warnings; \& \& use CGI::Session::ExpireSessions; \& use DBI; \& \& # \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& \& my($dbh) = DBI \-> connect \& ( \& \*(Aqdbi:mysql:aussi:127.0.0.1\*(Aq, \& \*(Aqroot\*(Aq, \& \*(Aqpass\*(Aq, \& { \& 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 => \*(Aq/tmp\*(Aq, 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. .Ve .SH "Description" .IX Header "Description" \&\f(CW\*(C`CGI::Session::ExpireSessions\*(C'\fR is a pure Perl module. .PP It deletes \f(CW\*(C`CGI::Session\*(C'\fR\-type sessions which have passed their use-by date. .PP It works with \f(CW\*(C`CGI::Session\*(C'\fR\-type sessions in a database or in disk files, but does not appear to work with \f(CW\*(C`CGI::Session::PureSQL\*(C'\fR\-type sessions. .PP The recommended way to use this module is via method \f(CW\*(C`expire_sessions()\*(C'\fR, which requires \&\f(CW\*(C`CGI::Session\*(C'\fR V 4 or later. .PP Sessions can be expired under one of three conditions: .IP "o You deem the session to be expired as of now" 4 .IX Item "o You deem the session to be expired as of now" .RS 4 .PD 0 .ie n .IP "o Methods: ""expire_db_sessions()"" and ""expire_file_sessions()""" 4 .el .IP "o Methods: \f(CWexpire_db_sessions()\fR and \f(CWexpire_file_sessions()\fR" 4 .IX Item "o Methods: expire_db_sessions() and expire_file_sessions()" .PD You want the session to be expired and hence deleted now because it's last access time is longer ago than the time you specify in the call to new, using the delta parameter. .Sp That is, delete the session because the time span, between the \f(CW\*(C`last access\*(C'\fR time and now, is greater than delta. .Sp In other words, force sessions to expire. .Sp The module has always used this condition to delete sessions. .ie n .IP "o Method: ""expire_sessions()""" 4 .el .IP "o Method: \f(CWexpire_sessions()\fR" 4 .IX Item "o Method: expire_sessions()" You want the session to be expired and hence deleted now because it's \f(CW\*(C`last access\*(C'\fR time is longer ago than the time you specify in the call to new, using the delta parameter. .RE .RS 4 .RE .IP "o The session has already expired" 4 .IX Item "o The session has already expired" This section applies to all 3 methods: \f(CW\*(C`expire_db_sessions()\*(C'\fR, \f(CW\*(C`expire_file_sessions()\*(C'\fR and \f(CW\*(C`expire_sessions()\*(C'\fR. .Sp This condition is new as of V 1.02. .Sp You want the session to be deleted now because it has already expired. .Sp That is, you want this module to delete the session, rather than getting \f(CW\*(C`CGI::Session\*(C'\fR to delete it, when \&\f(CW\*(C`CGI::Session\*(C'\fR would delete the session automatically if you used \f(CW\*(C`CGI::Session\*(C'\fR to retrieve the session. .Sp Note: This condition assumes the session's expiration time is defined (it does not have to be). .IP "o The file size is <= 5 bytes and was accessed more than 'delta' seconds ago" 4 .IX Item "o The file size is <= 5 bytes and was accessed more than 'delta' seconds ago" This condition is new as of V 1.03. .Sp This section applies to method: \f(CW\*(C`expire_file_sessions()\*(C'\fR. .Sp See below for how to provide a value of delta to the constructor. .Sp Old versions of \f(CW\*(C`CGI::Session\*(C'\fR sometimes create a file of size 0 bytes, so this test checks for such files, and deletes them if they are old enough. .PP Sessions are deleted if any of these conditions is true. .PP Sessions are deleted from the 'sessions' table in the database, or from the temp directory, depending on how you use \f(CW\*(C`CGI::Session\*(C'\fR. .SH "Distributions" .IX Header "Distributions" This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file. .PP See http://savage.net.au/Perl\-modules.html for details. .PP See http://savage.net.au/Perl\-modules/html/installing\-a\-module.html for help on unpacking and installing each type of distro. .SH "Security" .IX Header "Security" For file-based sessions, method \f(CW\*(C`expire_file_sessions()\*(C'\fR parses the contents of the file, using eval{}, in an attempt to determine the access and expiration times recorded within the file. .PP So, if you are uneasy about the security implication of this (as you should be), don't use this method. Use method \f(CW\*(C`expire_sessions()\*(C'\fR instead. The latter is a much more sophisticated way of expiring sessions, but it does require \f(CW\*(C`CGI::Session\*(C'\fR V 4 or later. .SH "Constructor and initialization" .IX Header "Constructor and initialization" new(...) returns a \f(CW\*(C`CGI::Session::ExpireSessions\*(C'\fR object. .PP This is the class's contructor. .PP Usage: CGI::Session::ExpireSessions \-> \fBnew()\fR. .PP This method takes a set of parameters. Only some of these parameters are mandatory. .PP For each parameter, call method \f(CW\*(C`new()\*(C'\fR as new(param_1 => value_1, param_2 => value_2, ...). .PP Note: As of V 1.07 of this module, you may call method \f(CW\*(C`set()\*(C'\fR to set parameters after calling method \f(CW\*(C`new()\*(C'\fR. .PP Not only that, but you may pass into all of the 3 methods \f(CW\*(C`expire_db_sessions()\*(C'\fR, \&\f(CW\*(C`expire_file_sessions()\*(C'\fR and \f(CW\*(C`expire_sessions()\*(C'\fR any of the parameters accepted by \f(CW\*(C`new()\*(C'\fR, since these 3 methods call \f(CW\*(C`set()\*(C'\fR if their caller provides parameters. .PP Parameters which can be used with \f(CW\*(C`new()\*(C'\fR, \f(CW\*(C`set()\*(C'\fR, or \f(CW\*(C`expire_*()\*(C'\fR: .IP "o cgi_session_dsn" 4 .IX Item "o cgi_session_dsn" This is the \s-1DSN\s0 (Data Source Name) used by \f(CW\*(C`CGI::Session\*(C'\fR to control what type of sessions you previously created and what type of sessions you now wish to expire. .Sp Do not confuse this with the \s-1DSN\s0 used by \f(CW\*(C`CGI::Session\*(C'\fR's method find(param_1, \e&sub, {DataSource => other_dsn...}, ...) when referring to db-based sessions. .Sp Method \f(CW\*(C`expire_sessions()\*(C'\fR is the only method in this module which uses this parameter. .Sp So, when you call \f(CW\*(C`expire_sessions()\*(C'\fR, this parameter \- cgi_session_dsn \- determines the set of sessions processed by, and possibly expired by, the call to \f(CW\*(C`expire_sessions()\*(C'\fR. .Sp The default value is undef, which means \f(CW\*(C`CGI::Session\*(C'\fR defaults to file-based sessions. .Sp This parameter is optional for file-based sessions, and mandatory for db-based sessions. .IP "o dbh" 4 .IX Item "o dbh" This is a database handle for the database containing the table 'sessions'. .Sp Either this parameter is mandatory, or the temp_dir parameter is mandatory. .IP "o delta" 4 .IX Item "o delta" .RS 4 .PD 0 .ie n .IP "o Methods: ""expire_db_sessions()"" and ""expire_file_sessions()""" 4 .el .IP "o Methods: \f(CWexpire_db_sessions()\fR and \f(CWexpire_file_sessions()\fR" 4 .IX Item "o Methods: expire_db_sessions() and expire_file_sessions()" .PD This is the number of seconds since the \f(CW\*(C`last access\*(C'\fR to the session, which determines whether or not the session will be expired. .ie n .IP "o Method: ""expire_sessions()""" 4 .el .IP "o Method: \f(CWexpire_sessions()\fR" 4 .IX Item "o Method: expire_sessions()" This is the number of seconds since the \f(CW\*(C`last access\*(C'\fR time of the session, which determines whether or not the session will be expired. .RE .RS 4 .Sp The default value is 2 * 24 * 60 * 60, which is the number of seconds in 2 days. .Sp By default, then, sessions which were last accessed more than 2 days ago are expired. .Sp This parameter is optional. .RE .IP "o dsn_args" 4 .IX Item "o dsn_args" If your cgi_session_dsn uses file-based storage, then this hashref might contain keys such as: .Sp .Vb 5 \& { \& Directory => Value 1, \& NoFlock => Value 2, \& UMask => Value 3 \& } .Ve .Sp If your cgi_session_dsn uses db-based storage, then this hashref contains (up to) 3 keys, and looks like: .Sp .Vb 5 \& { \& DataSource => Value 1, \& User => Value 2, \& Password => Value 3 \& } .Ve .Sp These 3 form the \s-1DSN,\s0 username and password used by \s-1DBI\s0 to control access to your database server, and hence are only relevant when using db-based sessions. .Sp Method \f(CW\*(C`expire_sessions()\*(C'\fR is the only method in this module which uses the parameter dsn_args. .Sp The default value for this parameter is undef. .Sp These parameters are optional for file-based sessions, and mandatory for db-based sessions. .IP "o table_name" 4 .IX Item "o table_name" This is the name of the database table used to hold the sessions. .Sp The default value is 'sessions'. .Sp This parameter is optional. .IP "o temp_dir" 4 .IX Item "o temp_dir" This is the name of the temp directory where you store CGI::Session\-type session files. .Sp The default value is '/tmp'. .Sp Either this parameter is mandatory, or the dbh parameter is mandatory. .IP "o time" 4 .IX Item "o time" The session's \f(CW\*(C`last access\*(C'\fR time is subtracted from the value of this parameter, and if the result is greater than or equal to the value of parameter 'delta', then the session is expired. .Sp Method \f(CW\*(C`expire_sessions()\*(C'\fR is the only method in this module which uses this parameter. .Sp The default value is obtained by calling \fBtime()\fR. .Sp This parameter is optional. .IP "o verbose" 4 .IX Item "o verbose" This is a integer, 0 or 1, which \- when set to 1 \- causes progress messages to be written to \s-1STDOUT.\s0 .Sp The default value is 0. .Sp This parameter is optional. .SH "Method: \fBexpire_db_sessions()\fP" .IX Header "Method: expire_db_sessions()" Returns nothing. .PP This method uses the dbh parameter passed to \f(CW\*(C`new()\*(C'\fR to delete database-type sessions. .SH "Method: \fBexpire_file_sessions()\fP" .IX Header "Method: expire_file_sessions()" Returns nothing. .PP This method uses the temp_dir parameter passed to \f(CW\*(C`new()\*(C'\fR to delete file-type sessions. .SH "Method: \fBexpire_sessions()\fP" .IX Header "Method: expire_sessions()" Return value: .IP "o undef" 4 .IX Item "o undef" Returns undef if your version of \f(CW\*(C`CGI::Session\*(C'\fR does not support method \f(CW\*(C`find()\*(C'\fR. .Sp Also, returns undef when \f(CW\*(C`CGI::Session\*(C'\fR's method \f(CW\*(C`find()\*(C'\fR failed for some reason. .IP "o 1" 4 .IX Item "o 1" Returns 1 when \f(CW\*(C`find()\*(C'\fR succeeds. .PP Returns the result of calling CGI::Session's method \fBfind()\fR, which will be undef for some sort of failure, and 1 for success. .PP This method handles both file-based and db-based sessions. .SH "Example code" .IX Header "Example code" See the examples/ directory in the distro. .PP There are 2 demo programs: expire\-sessions.pl and expire\-set.pl. .SH "SUPPORT" .IX Header "SUPPORT" Bugs should be reported via the \s-1CPAN\s0 bug tracker at .PP .SH "REPOSITORY" .IX Header "REPOSITORY" . .SH "Author" .IX Header "Author" \&\f(CW\*(C`CGI::Session::ExpireSessions\*(C'\fR was written by Ron Savage \fI\fR in 2004. .PP Home page: http://savage.net.au/index.html .SH "Copyright" .IX Header "Copyright" Australian copyright (c) 2004, Ron Savage. All Programs of mine are '\s-1OSI\s0 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