In response to delete session using CGI::Session I put together a snippet which uses CGI::Session to delete expired session files. It suffers from the unfortunate side effect that the last access time will be updated for un-expired sessions.
This new snippet below solves that problem by not using CGI::Session at all. However, it assumes that you're using the default serialization method and the default file naming scheme.
Note: it has been minimally tested on my part. It's probably not suitable for use in a production environment in its current state.
update, (10/09/2003): added "or die" to open. Fixed eval(). Tested w/ perl 5.8.0 on win2k.
use strict; use File::Find; use constant SESSION_DIR => '/temp/'; find( \&wanted, SESSION_DIR ); sub wanted { return unless /^cgisess_(.*)/; open( FILE, SESSION_DIR . $_ ) or die "Cannot open session $1: $!" +; my $data; { local $/; $data = <FILE>; } close( FILE ); my $D; eval( $data ); if ( time() >= $D->{ _SESSION_ETIME } + $D->{ _SESSION_ATIME } ) { unlink( SESSION_DIR . $_ ) or die "Cannot delete session $1: +$!"; print "$1\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delete expired CGI::Session files
by Anonymous Monk on Oct 09, 2003 at 08:08 UTC | |
|
Re: Delete expired CGI::Session files
by Anonymous Monk on Nov 12, 2003 at 18:08 UTC | |
by LTjake (Prior) on Nov 12, 2003 at 18:47 UTC | |
by Anonymous Monk on Nov 13, 2003 at 13:50 UTC |