-
-
$nowtime=time(); - $pastsec = $nowtime – $_GET["t"];
if($ pastsec<60) - {
- exit; //Update once every minute, the time can be adjusted by yourself
- }
ob_start(); //Open the buffer
- include("index.php") ;
- $content = ob_get_contents(); //Get the contents of the buffer
- $content .= “n
file_put_contents("index.html",$content);
if (!function_exists(" file_get_contents"))
- {
- function file_get_contents($fn,$fs)
- {
- $fp=fopen($fn,"w+");
- fputs($fp,$fs);
- fclose($fp);
- }
- }
- ?>
-
-
Copy code
Notes:
Three functions: ob_start(), ob_end_clean(), ob_get_contents()
ob_start(): Opens the buffer, which is to cache the content of the static file you need to generate here;
ob_get_contents(): reads the contents in the buffer. The following code is an example;
ob_end_clean(): This is more important. Only after using this function, the contents of the buffer will be read;
-
-
if(file_exists("./index.htm"))//Check whether the static index.htm file exists - {
- $time=time();< ;/p>
//If the file modification time is different from the current time?, direct to the htm file, otherwise regenerate htm
- if($time-filemtime("./index.htm")< 600)
- {
- header("Location:classhtml/main.htm");
}
- }
//Add ob_start() at the beginning of your ;
- ob_start();
//The content of the homepage is your dynamic part
//Add ob_end_clean() at the end and replace this page Output to a variable
- $temp=ob_get_contents();
- ob_end_clean();
//Write to file
- $fp=fopen("./index.htm",'w' );
- fwrite($fp,$temp) or die('Write file error');
- //echo "Generating HTML completed!";
- ?>
-
Copy code
|