IT备忘录

您现在的位置是:首页 > 教程 > 建站教程

建站教程

帝国CMS自动刷新生成首页代码和方法

2022-07-28 16:29:10建站教程
一般来说,我们使用帝国CMS建站系统都是采用静态生成html页面的方式,这样可以大大的节约服务器开销,在某些特殊情况下,我们的需求是让帝国CMS自动刷新生成首页,那么问题来了,我们该

一般来说,我们使用帝国CMS建站系统都是采用静态生成html页面的方式,这样可以大大的节约服务器开销,在某些特殊情况下,我们的需求是让帝国CMS自动刷新生成首页,那么问题来了,我们该如何实现了?下面IT备忘录小编就给大家分享解决方法。

帝国CMS自动刷新生成首页代码和方法

方法步骤:

方法一:

采用:登陆后台->系统设置->“管理计划任务”->“增加计划任务”,但是这种官方提示需要登录后台的情况下才可以。

方法二:

1、在 /e/ 建立文件夹 autohtml 并设置 777权限(可读写),将下面代码保存在 /e/autohtml/index_html.php,修改刷新时间,将文件中:600,改为你想要的时间,单位为:

<?php
require("../class/connect.php");
include("../class/db_sql.php");
include("../class/config.php");
include("../class/functions.php");
include("../class/t_functions.php");
require LoadLang("pub/fun.php");
require("../data/dbcache/class.php");
require("../data/dbcache/MemberLevel.php");
include("../class/chtmlfun.php");
$link=db_connect();
$empire=new mysqlquery();
$filepath_s="indexhtmlhc.txt";
$time=time();
@$filemtime=(int)filemtime($filepath_s)+600;
/*
函数解释
file_exists() 函数检查文件或目录是否存在。
mkdir() 函数创建目录。
time() 函数返回当前时间的 Unix 时间戳。
filemtime() 函数返回文件内容上次的修改时间。
*/
if (!file_exists($filepath_s)){
fopen($filepath_s, 'w');
@chmod($filepath_s, 0777);
ReIndex();
}elseif(!file_exists($filepath_s) || (filemtime($filepath_s)+600)<time()){
fopen($filepath_s, 'w');
@chmod($filepath_s, 0777);
ReIndex();
}else{
// do nothing
}
db_close();
$empire=null;
?>

2、再将以下代码插入:首页模板 底部即可,当有访客访问网站的时候就会触发机制。

<script language="javascript" type="text/javascript" src="/e/autohtml/index_html.php"></script>

温馨提示

1、大家可以自行修改文件的存放路径。

2、其实第二段代码也可以不放到网站首页模板,用宝塔面板的用户可以在面板上增加此链接的计划任务,设置好间隔时间即可。

相关内容标签

文章评论