phpwind的rewrite重寫原理
就是一般我們用echo print 輸出字符到頁面上的時候,意味著只要執(zhí)行到了echo,php就會立即輸出到客戶端,但php有幾個和緩沖相關(guān)的函數(shù),他可以控制你輸出的行為,就是不立馬輸出,而是等你調(diào)用了ob_flush/flush函數(shù),才輸出。而pw就是利用了這個原理,等頁面所有的內(nèi)容都生成完畢了,最后調(diào)footer()時,ob_get_contents(),獲取緩沖的內(nèi)容,通過正則批量替換url,構(gòu)造rewrite的url格式。
關(guān)于ob,其實有兩種主要的使用場景,一個是實現(xiàn)頁面壓縮輸出 - ob_gzhandler;再一個是在ajax/自定義api返回數(shù)據(jù)時,程序執(zhí)行過程中,你不知道前面的程序是否有些意外的輸出字符如空格、空行等,他們在數(shù)據(jù)返回時會造成很多意外情況,所以可以在你輸出數(shù)據(jù)前,清除前面的緩沖內(nèi)容,重新開始輸出。
官方默認(rèn)的重寫規(guī)則(注:重寫是web服務(wù)器 - 如apache、nginx或應(yīng)用容器tomcat的功能,不是程序語言自己的功能),如pw的一條重寫規(guī)則 - apache:
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
首先,我們分析他的構(gòu)成。當(dāng)我們打開 global.php 文件,找到 :
<?php
$db_obstart == 1 ? ob_start('ob_gzhandler') : ob_start();
?>
我們會發(fā)現(xiàn),這個全局文件打開了一個ob_start,并且進行一些判斷。這個是pw系統(tǒng)進行rewrite的一個關(guān)鍵。
然后我們再找到footer()函數(shù):
<?php
function footer(){
global $db,$db_obstart,$db_footertime,$db_htmifopen,$P_S_T,$mtablewidth,$db_ceoconnect,$wind_version,$imgpath,$stylepath,$footer_ad,$db_union,$dbinfo,$timestamp;
Update_ol();
if($db){
$qn=$db->query_num;
}
$ft_gzip=($db_obstart==1 ? "Gzip enabled" : "Gzip disabled").$db_union[3];
if ($db_footertime == 1){
$t_array = explode(' ',microtime());
$totaltime = number_format(($t_array[0]+$t_array[1]-$P_S_T),6);
$wind_spend = "Total $totaltime(s) query $qn,";
}
$ft_time=get_date($timestamp,'m-d H:i');
include PrintEot('footer');
$output = str_replace(array('<!--<!---->','<!---->'),array('',''),ob_get_contents());
if($db_htmifopen){
$output = preg_replace(
"/<a(s*[^>]+s*)href=(["|']?)([^"'>s]+.php?[^"'>s]+)(["|']?)/ies",
"Htm_cv('3','<a1href="')",
$output
);
}
ob_end_clean();
$db_obstart == 1 ? ob_start('ob_gzhandler') : ob_start();
echo $output;
flush;
exit;
}
?>
common.php中:
function parseHtmlUrlRewrite($html, $flag) {
return $flag ? preg_replace("/\<a(\s*[^\>]+\s*)href\=([\"|\']?)((index|cate|thread|read|faq|rss)\.php\?[^\"\'>\s]+\s?)[\"|\']?/ies", "Htm_cv('\\3','<a\\1href=\"')", $html) : $html;
}</p> <p>/**
* url處理
*
* @param string $url
* @param string $tag
* @return string
*/
function Htm_cv($url, $tag) {
return stripslashes($tag) . urlRewrite($url) . '"';
}</p> <p>function urlRewrite($url) {
global $db_htmifopen, $db_dir, $db_ext;
if (!$db_htmifopen) return $url;
$tmppos = strpos($url, '#');
$add = $tmppos !== false ? substr($url, $tmppos) : '';
$turl = str_replace(array('.php?', '=', '&', '&', $add), array($db_dir, '-', '-', '-', ''), $url);//pw的重寫規(guī)則在這里進行字符的替換
$turl != $url && $turl .= $db_ext;
return $turl . $add;
}
上一篇:沒有了
欄 目:phpwind
下一篇:沒有了
本文標(biāo)題:phpwind的rewrite重寫原理
本文地址:http://www.jygsgssxh.com/a1/phpwind/13034.html
您可能感興趣的文章
- 01-11phpwind發(fā)帖 自動分析url|使用簽名如何默認(rèn)不選中
 - 01-11phpwind 今日發(fā)貼數(shù)量不顯示解決
 - 01-11phpwind 系統(tǒng)強制您所在的用戶組必須設(shè)置安全問題
 - 01-11無心寵物2.3 PHPWIND7.0/6.X通用版插件
 - 01-11PHPWind7.0風(fēng)格css樣式詳解
 - 01-11phpwind支付成功后收不到交易幣的解決方案
 - 01-11phpwind解決搜索到回收站中內(nèi)容的問題
 - 01-11phpwind的wap中帖子訪問權(quán)限問題
 - 01-11phpwind前臺銀行操作日志鏈接問題
 - 01-11phpwind后臺刪除用戶點選“直接刪除”出錯問題
 


閱讀排行
本欄相關(guān)
- 01-11phpwind發(fā)帖 自動分析url|使用簽名如何
 - 01-11phpwind 今日發(fā)貼數(shù)量不顯示解決
 - 01-11phpwind 系統(tǒng)強制您所在的用戶組必須設(shè)
 - 01-11無心寵物2.3 PHPWIND7.0/6.X通用版插件
 - 01-11PHPWind7.0風(fēng)格css樣式詳解
 - 01-11無心寵物帖子內(nèi)顯示(玫瑰花 版)
 - 01-11phpwind支付成功后收不到交易幣的解決
 - 01-11phpwind解決搜索到回收站中內(nèi)容的問題
 - 01-11phpwind的wap中帖子訪問權(quán)限問題
 - 01-11phpwind前臺銀行操作日志鏈接問題
 
隨機閱讀
- 08-05織夢dedecms什么時候用欄目交叉功能?
 - 01-10C#中split用法實例總結(jié)
 - 08-05DEDE織夢data目錄下的sessions文件夾有什
 - 01-10delphi制作wav文件的方法
 - 04-02jquery與jsp,用jquery
 - 01-10使用C語言求解撲克牌的順子及n個骰子
 - 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
 - 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
 - 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
 - 01-11ajax實現(xiàn)頁面的局部加載
 


