Forum Moderators: coopster

Message Too Old, No Replies

Problems with old PHP Sessions

Problems with old PHP Sessions don't delete

         

RedBaron

3:55 am on May 10, 2006 (gmt 0)

10+ Year Member



Once again in my quest to switch from ASP to PHP I turn to the experts here at WebmasterWorld.com to guide me to an enlightened state.

I've created a password protected area for my website and it sometimes works. Basically, if I open FTP and delete any/all php sessions in my sessions folder prior to loging into my site it works fine... lol. For some reason the old session file(s) cause any new logins not to work.

If nothing else, is there a way I could run a batch file to delete old session when people visit the login page?

Here are a few things I've tried, any suggestions will be greatly appreciated.

[bugs.php.net...]

Google groups [groups.google.com]

Thanks,
RedBaron

[edited by: jatar_k at 2:51 pm (utc) on May 10, 2006]
[edit reason] fixed sidescroll [/edit]

RedBaron

5:04 am on May 10, 2006 (gmt 0)

10+ Year Member



:D I think i solved my problem! I noticed everytime junk sessions were left in my sessions folder the session files were either 0 bites or 20 something bites so I coded the following to delete any session files <= 29 bites.

<?php
$path = "sessionfolder/";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)){
/* IGNORE '.' UP DIRECTORIES */
if ($file!="." && $file!=".."){
/* IF SESSION IS <= 29 BITES THEN IT CONTAINS NO DATA SO DELETE IT*/
if (filesize($path.$file) <= 29){
return unlink($path.$file);
}
}
}
closedir($dir_handle);
?>

I am so proud of myself for figuring this one out :) but if there is a better way please let me know.