本文共 1659 字,大约阅读时间需要 5 分钟。
帝国CMS 自动刷新首页对于部份使用帝国程序的网友或许非常有用。刚看到一篇文章, 主要介绍了javascript与php结合的实现前台自动刷新首页的功能。就算一种方法吧。推荐我喜欢的第二种办法.
第一种方法,摘自网上,粗略看了下。
在 /e/ 建立文件夹 htmlindex 并设置 777权限,将下面代码保存在 /e/htmlindex/index_html.php,修改刷新时间,将文件中1200改为你想要的时间,单位为秒.
代码如下:
###<?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)+1200;
/*
函数解释
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)+1200)
fopen($filepath_s, 'w');
@chmod($filepath_s, 0777);
ReIndex();
}else{
// do nothing
}
db_close();
$empire=null;
?>###网上流传的是这种办法,懂得自然懂,非常不建议使用!
建议使用以下第二种办法,
就参照上边这个php文件,主要就是个ReIndex()自动刷新函数,具体原理见代码!WINdow系统可以使用自动定时工具(恰好,本站有一个http://www.lj55.net/mysoft/21.html),LINUX建议使用面板里的计划任务。相比较上述办法,非常节约网站资源!
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();
ReIndex();
db_close();
$empire=null;
?>
转载地址:https://blog.csdn.net/weixin_34163020/article/details/117758496 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!