in reply to Re: Printing files age information help!
in thread Printing files age information help!

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.
  • Comment on Re^2: Printing files age information help!

Replies are listed 'Best First'.
Re^3: Printing files age information help!
by Anonymous Monk on Jan 16, 2011 at 19:11 UTC
    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!
        Any suggestions? Thanks!

        Get rid of all opendir/readdir... its just clutter

        If you want CGI::Session to look for sessions $dir_session, you have to call ->find with the appropriate arguments