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

來源:互聯網
上載者:User

 <?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處理尾
?>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.