in reply to Printing files age information help!

Why are you avoiding using CGI::Session?
  • Comment on Re: Printing files age information help!

Replies are listed 'Best First'.
Re^2: Printing files age information help!
by Anonymous Monk on Jan 16, 2011 at 19:00 UTC
    Honestly I tried but couldn't get to delete the sessions in the directory specific. My plan is to find the sessions older than a specific time and use "unlink" to manually delete old left sessions by the user.
      But CGI::Session->find does work, and does delete old sessions without compunction
        Hi, I've tried deleting the sessions with something like this, and no success:
        #!/usr/bin/perl -w use strict; use CGI qw(-oldstyle_urls :standard); use CGI::Carp qw(fatalsToBrowser); use File::Find; use File::stat; use Time::localtime; my $mytime=(time); my $file_stat; my $dir_session = "../sessions"; print header(); opendir(DIR, $dir_session) or die "Couldn't open directory, $!"; while (my $sessions = readdir DIR) { if($sessions=~ /^cgisess_[a-f0-9]{32}$/) { CGI::Session->find( \&purge ); } } closedir DIR; sub purge { my ($session) = @_; next if $session->is_empty; # <-- already expired?! if ( ($session->ctime + 60*55) <= time() ) { $session->delete(); $session->flush(); # Recommended practice says use flush() + after delete(). } }

        Any suggestions? Thanks!