首页index.php代码:
<?php ob_start();?> <?php if(file_exists("index.html")){ // 看静态index.htm文件是否存在 $time1 = time(); $time2 = filemtime("index.html"); //echo($time1-$time2); // 文件修改时间和现在时间相差?的话,直接导向html文件,否则重新生成html if(($time1 - $time2) < 600) header("Location:index.html"); } ?>代码二:
<html> <body> <h1>It works!</h1> </body> </html>代码三:
<?php //首页内容,就是你的动态部分了 //在结尾加入ob_end_clean(),并把本页输出到一个变量中 $temp=ob_get_contents(); ob_end_clean(); //写入文件 $fp=fopen("index.html",'w'); fwrite($fp,$temp) or die('写文件错误'); //初始显示 echo($temp); ?>