Hi guys:
I am trying to implement some commonly published cache control code using a PHP script attached.
It appears to be almost working. The problem I am having is that the variable
$reqfilename
does not appear to be getting set.
I am not a PHP programmer, and am probably missing something fundamental
Can someone tell me how to properly set this variable in this code?
I am running Apache for my webserver.
<?php
$cachefile = "cache/".$reqfilename.".html";
// Serve from the cache if it is the same age or younger than the last
// modification time of the included file (includes/$reqfilename)
if (file_exists($cachefile) && (filemtime("includes/".$reqfilename) < filemtime($cachefile))) {
include($cachefile);
echo "<!-- Cached ".date('H:i', filemtime($cachefile))."-->\n";
exit;
}
//else
// start the output buffer
ob_start();
?>
// Normal HTML here
<?php
// PHP, open the cache file for writing
$fp = fopen($cachefile, 'w');
// save the contents of output buffer to the file
fwrite($fp, ob_get_contents());
// close the file
fclose($fp);
// Send the output to the browser
ob_end_flush();
?>