The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CGI::Session::ExpireSessions - Expires CGI::Session 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();

Description

CGI::Session::ExpireSessions is a pure Perl module.

It does no more than expire CGI::Session-type sessions which have passed their use-by date.

Expiring a session means deleting that session from the 'sessions' table in the database, or deleting that session from the temp directory, depending on how you use CGI::Session.

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.

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.

Constructor and initialization

new(...) 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 you wish to use, call new as new(param_1 => value_1, ...).

dbh

This is a database handle for the database containing the table 'sessions'.

Either this parameter is mandatory, or the temp_dir parameter is mandatory.

delta

This is the number of seconds after the last access to the session, which determines whether or not the session will be expired.

The default value is 2 * 24 * 60 * 60, which is the number of seconds in 2 days.

Sessions which were last accessed more than 2 days ago are expired.

This parameter is optional.

temp_dir

This is the name of the temp directory where you store CGI::Session-type session files.

The default value is '/tmp'.

Either this parameter is mandatory, or the dbh parameter is mandatory.

verbose

This is a integer, 0 or 1, which - when set to 1 - causes progress messages to be written to STDOUT.

The default value is 0.

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.

Example code

See the examples/ directory in the distro.

There is 1 demo file: expire-sessions.pl.

Related Modules

CGI::Session

Required Modules

Carp

Author

CGI::Session::ExpireSessions was written by Ron Savage <ron@savage.net.au> in 2004.

Home page: http://savage.net.au/index.html

Copyright

Australian copyright (c) 2004, Ron Savage. All rights reserved.

        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