Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi::session session cleanup..

Status
Not open for further replies.

travs69

MIS
Joined
Dec 21, 2006
Messages
1,431
Location
US
If you are running cgi::session using files how are you handling old session files hanging around? I have no problem writing something that looks to see if the files >3 hours old and deleting it.. but I just figured there might be something built into cgi::session to do it for me. I plan on migrating to a DBI instead of files. Will I still have to do my old cleanup?
 
I just found
CGI::Session::ExpireSessions

but didn't know if anyone was using it and if they had any comments..
 
I have a chat that writes session and I remove them this way

Code:
my $my_session_dir = my/path

sub RemoveOldSessions
{
local(@files, $file);
# Open up the session directory.
opendir(SESSIONDIR, "$my_session_dir");
# read all entries except "." and ".."
@files = grep(!/^\.\.?$/,readdir(SESSIONDIR));
closedir(SESSIONDIR);                 
                         
# Go through each file
foreach $file (@files)
        {
# If it is older than session_length, delete it
# Note that the filename needs to be untainted before removing.
        if ($file =~ /([\w-.]+)/) {
            $file = $1;
        } else {
            $file = ".dat";
        }
        if (-M "$my_session_dir/$file" > $my_session_length)
                {
                unlink("$my_session_dir/$file");
                }

        }
} # End of RemoveOldSessions

MA WarGod

I believe if someone can think it, it can be programmed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top