Inhaltsverzeichnis
" >2. [代码][PHP]代码   
Heim php教程 PHP源码 把当前显示的动态PHP页面静态化,生成HTML文件

把当前显示的动态PHP页面静态化,生成HTML文件

May 25, 2016 pm 05:04 PM


/*
**此段代码要放在所有页面都包含的模块里
**比如const.php或conn.php
**$isHTMLModel 此变量设置是否保存页面内容为静态文件
**$spacing 此变量设置更新时间
**$HtmlPath 此变量保存当前显示的页面的静态文件的路径
**UseHtmlPage 此函数的作用主要是判断当前页面的HTML静态文件是否过期,是则返回文件路径
*/
$isHTMLModel=0;//是否使用静态化页面
$spacing=1;//生成新的文件更新间隔时间 单位:小时
$HtmlPath=UseHtmlPage($isHTMLModel,$spacing);



/*
**此段代码放在需要输出静态文件的页面最底部
**主要作用就是根据上面的设置参数,把当前动态页面里显示过的内容
**生成为静态HTML文件,保存的静态文件的路径在$HtmlPath里
*/
CreateHtmlPage($HtmlPath , $isHTMLModel)
Nach dem Login kopieren

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); 	
	}
}
Nach dem Login kopieren

           

       

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
2 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Repo: Wie man Teamkollegen wiederbelebt
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)