首页 » 收集 » 正文内容
Typecho生成静态首页index.html文件
寻梦xunm| 627| 收集
2年前
超过1092天 温馨提示
本文最后更新于2021年09月24日,已超过1092天没有更新,若内容或图片失效,请留言反馈。

在挨踢路看到的教程,不仅仅适用于Typecho,wordpress也是可以通用。

教程
在网站根目录新建文件f5.php然后里面写入下面的代码。

<?php
$nowtime=time();
$pastsec = $nowtime - $_GET["t"];
if($pastsec<600)
{
exit; //10分钟更新一次,时间可以自己调整
}
ob_start(); //打开缓冲区
include("index.php");
$content = ob_get_contents(); //得到缓冲区的内容
$content .= "\n<script language=javascript src=\"f5.php?t=".$nowtime."\"></script>"; //加上调用更新程序的代码

file_put_contents("index.html",$content);
if (!function_exists("file_put_contents"))
{
function file_put_contents($fn,$fs)
{
$fp=fopen($fn,"w+");
fputs($fp,$fs);
fclose($fp);  
}
}
?>

然后浏览器打开你的域名/f5.php,打开后你将看到的还是你的首页,刷新你的网站根目录,看到一个index.html就说明生成成功了,然后查看首页代码,末尾出现“

Q Q:1340326824
邮箱:vipshiyi@qq.com
QQ群:422720328

我的音乐

微博客-专为自己编写开发的源码