<?php

$file = "index.html";
$stat = stat($file);
// cache every 30 secs
if((time() - $stat['mtime']) > 30) {

	$url = "http://kaspur.xs4all.nl/pub/tracker/update.php" ;
	// set URL and other appropriate options
	writeToFile($file, @file_get_contents($url));
	$cached =  "cached @ " . date("F j, Y, g:i:s a", time());
}
else {
	$cached =  "cached @ " . date("F j, Y, g:i:s a", $stat['mtime']);
}
include($file);


//  statusmessage
echo "<center><font color=white>$cached</font></center>"; 
	function writeToFile ($filename, $content)
	{
		if (!file_exists($filename))
		{
			if (!$handle = fopen($filename, 'w'))
			{
				echo "Cannot open file ($filename)";
				exit;
			}
			else
			{
				fclose($handle);
				chmod($filename, 06666);
			}
		}
		
		if (!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		
			
		if (is_writable($filename))
		{
			if (fwrite($handle, $content) === FALSE)
			{
				echo "Cannot write to file ($filename)";
				exit;
			} 
			
			//print "File written : " . $filename . "<br>";
			flush();
			fclose($handle);
	
		}
		else
		{
			if (chmod($filename, 0666))
				writeToFile ($filename, $content);
		}
	}

?>