萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> 腳本Html教程 >> PHP動態網頁實現靜態HTML技術的方法

PHP動態網頁實現靜態HTML技術的方法

 <?php

/*____生成HTML文件________beign__________*/
if ($make_html)
{
$buffer = ob_get_flush();
if ($go_html)//是否直接轉到HTML文件顯示還是PHP讀得內容輸出(0:php讀內容輸出1:直接轉)
{
/*__處理因生成了HTML文件而產生的種徑問題______begin_______*/
$search = array(
"/(src=|action=|href=|ajaxRead()"/ie",
"/.../e",
"/././e",
"/../http:///ies",
"/../#/",
"/'.'/e",
"/../javascript:/ies");
$replace = array(
"'1"../'",
"'..'",
"'.'",
"'http://'",
"#",
"''..''",
"'javascript:'");
$buffer = preg_replace($search, $replace, $buffer);
/*___處理因生成了HTML文件而產生的種徑問題_____end_____*/
}
$fp = fopen(HTML_FILE, "w");
if ($fp)
{
fwrite($fp, $buffer);
fclose($fp);
}
}
/*_______生成HTML文件_________beign________*/
?>
<?php
ob_start();
/*____判斷是否已生成了HTML文件,若生成了則跳轉到HTML頁面___begin_____*/
$qstring = isset($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"] : "";
if ($qstring)//程序加了GET請求的處理
{
$qstring = str_replace("=", "", $qstring);
define("HTML_FILE", "./h/{$efilename}-{$qstring}.html");
}
else
{
define("HTML_FILE", "./h/{$efilename}.html");
}
if (file_exists(HTML_FILE))
{
$lcft = filemtime(HTML_FILE);//last create file time
if (($lcft + 3600) > time())//判斷上次生成HTML文件是否以過去1時間,若沒有才直接輸出文件內容
{
if ($show_html)//是否以HTML靜態頁面展示(0不以HTML展顯1以html展顯)
{
if ($go_html)//是否直接轉到HTML文件顯示還是PHP讀得內容輸出(0:php讀內容輸出1:直接轉)
{
header("Location: " . HTML_FILE);//直接轉
}
else
{
echo(file_get_contents(HTML_FILE));//讀出展顯
}
exit(0);
}
}
}
/*___判斷是否已生成了HTML文件,若生成了則跳轉到HTML頁面_____end_____*/
?>
<?php
require("woods-thtml.php");//生成HTML處理頭
//if (count($_GET) < 1 && count($_POST) < 1){require("woods-thtml.php");}//生成HTML處理頭
require("{$exec_file}");//注冊語言定義文件
foreach ($lang as $key => $value)
{
$atpl[strtoupper($key) ."_LANG"] = $value;
}
/*__________列表常識向上走的項_______end_______*/
include("woods-templates.php");
$tpl = new WoodsTpl("./templates/");
$tpl->require_tpl("header.html");
$tpl->set_file();
$tpl->block("EBCORP", $scorp);
$tpl->block("NEWS", $news);
$tpl->block("PRODUCT", $product);
$tpl->block("EBPNAME_MSG", $spname);
$tpl->block("LORE", $lore);
$tpl->require_tpl("footer.html");
$tpl->parse($atpl, true);
$tpl = NULL;
/*_____模板操作________end_____________*/
require("woods-bhtml.php");//生成HTML處理尾
?>

 

copyright © 萬盛學電腦網 all rights reserved