Exemple #1
0
header('ETag: "' . md5($mtime . $fileName) . '"');
// output last modified header using the last modified date of the file.
header('Last-Modified: ' . $gmt_mtime);
// this resource expires one month from now.
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $cacheTime) . ' GMT');
// tell all caches that this resource is publically cacheable.
header('Cache-Control: public,max-age=' . $cacheTime);
readfile($fileName);
// dump server params for debug purposes
/*
$dump = "------------------------------------\n";
foreach($_SERVER as $key => $value)
{
	$dump .= $key .": " . $value . "\n";
}
echo $dump;
*/
// try to log the download
$db = new DbMySql();
$remoteIp = isset($_SERVER["HTTP_X_REMOTE_ADDR"]) ? $_SERVER["HTTP_X_REMOTE_ADDR"] : (isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '???');
$userAgent = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : '???';
$type = $file_extension == "xml" ? "x" : "?";
list($msec, $sec) = explode(" ", microtime());
$micro = sprintf("%03d", (double) $msec * 1000);
$now = strftime("%Y%m%d%H%M%S") . $micro;
if ($type == "?") {
    $type = substr($page, 0, 1);
}
$query = "insert into DOWNLOAD_LOG(DATE_INSERT,TYPE,FILE,REMOTE_ADDRESS,USER_AGENT) values(" . "'" . $now . "'," . "'" . $type . "'," . "'" . $page . "'," . "'" . $remoteIp . "'," . "'" . $userAgent . "')";
$db->execQuery($query);
return;