/* **此段代码要放在所有页面都包含的模块里 **比如const.php或conn.php **$isHTMLModel 此变量设置是否保存页面内容为静态文件 **$spacing 此变量设置更新时间 **$HtmlPath 此变量保存当前显示的页面的静态文件的路径 **UseHtmlPage 此函数的作用主要是判断当前页面的HTML静态文件是否过期,是则返回文件路径 */ $isHTMLModel=0;//是否使用静态化页面 $spacing=1;//生成新的文件更新间隔时间 单位:小时 $HtmlPath=UseHtmlPage($isHTMLModel,$spacing); /* **此段代码放在需要输出静态文件的页面最底部 **主要作用就是根据上面的设置参数,把当前动态页面里显示过的内容 **生成为静态HTML文件,保存的静态文件的路径在$HtmlPath里 */ CreateHtmlPage($HtmlPath , $isHTMLModel)
2. [代码][PHP]代码
//如果使用静态页面则取得当前页面的路径,并判断是否存在静态文件和文件的生成日期时间戳与当前日期时间戳是否相差$spacing这么多,有则跳转,无有则生成静态文件路径 function UseHtmlPage($isHTMLModel,$spacing){ if ($isHTMLModel){ $paramet=""; $paramet=$_SERVER['QUERY_STRING']; if($paramet!="") $paramet="=".str_replace("=","-",str_replace("&","_",$_SERVER['QUERY_STRING'])).""; $HtmlPath=dirname($_SERVER["SCRIPT_FILENAME"])."\\html".str_replace(".php",$paramet.".html",str_replace("/","\\",$_SERVER["PHP_SELF"])); $Path="/html".str_replace(".php",$paramet.".html",$_SERVER["PHP_SELF"]); if(file_exists($HtmlPath)){ $one = strtotime(date('r', filemtime($HtmlPath)));//文件之前 时间戳 $two = time();//系统现在 时间戳 $cle = $two - $one; //得出时间戳差值 if ($H<$spacing) {header("Location: ".$Path);} } return $HtmlPath; } } //如果使用静态页面并且有静态文件路径,则把当前页面的缓存写到静态文件中 function CreateHtmlPage($HtmlPath , $isHTMLModel){ if ($isHTMLModel) WriteHtml($HtmlPath); } //把当前页面的缓存写到静态文件中 function WriteHtml($filepath){ if($filepath!=""){ $content = ob_get_contents();//取得php页面输出的全部内容 ob_flush(); @unlink($filepath); $fp = fopen($filepath, "w"); //创建一个文件,并打开,准备写入 fwrite($fp, $content); //把php页面的内容全部写入 fclose($fp); } }
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Saving in R.E.P.O. Explained (And Save Files)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.