#native_company# #native_desc#
#native_cta#

Windows cron job for session

By Christof
on June 4, 2003

Version: 1.0

Type: Sample Code (HOWTO)

Category: File Management

License: GNU General Public License

Description: This cron will do the same on Windows as session management works on Linux

// ************christof's Simple Windows 2k Con Job****************** 
// set the task scheduler in windows 
// C:PHPphp.exe -q C:roottotheSessionsCron.php
// set you time to always run more frequently than your session lifetime below E.G. Every day, every 15 minutes for 24 hours
// enable the task password with your normal OS admin logins
// make sure the C:PHPsessiondata is authorized for R-W or which ever folder you storing your sessions in.
$ThisDir = "C:PHPsessiondata";
$ThisFile = "C:PHPsessiondata";
$SessName = "";

//if you need a database section cleared as well, else comment this out
$MyConn = mysql_connect("host", "user", "pass"); 
mysql_select_db("myDB", $MyConn);

	$handle=opendir($ThisDir); 
	while (false!==($file = readdir($handle))) 
	{ 
		if ($file != "." && $file != "..")
		{
		clearstatcache();
		$ThisFile .= $file;
		$SessName = $file;
		$StatArr = stat($ThisFile);
		$LastAccessedTime = date("H:i:s", $StatArr[9]);
		$NowTime = date("H:i:s");
		$s = strtotime($NowTime) - strtotime($LastAccessedTime);
		$d = intval($s/86400); 
 		$s -= $d*86400;
 		$h = intval($s/3600);
 		$s -= $h*3600;
 		$m = intval($s/60); 
 		$s -= $m*60;
 			if($m >= 20)//lifetime of session in minutes - how long a session may exist for
			{
			unlink($ThisFile);//delete the session file 
			//if you need a database section cleared as well, else comment this out
			$result = mysql_query("DELETE FROM loggedinusers WHERE sessionid = '$SessName'", $MyConn); 
			}
		$ThisFile = "C:PHPsessiondata"; //reset the root again
		}
	} 
	closedir($handle);
	//if you need a database section cleared as well, else comment this out
	mysql_close($MyConn);