国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

phpwind的rewrite重寫原理

2024-04-25 20:33:05
字體:
來源:轉載
供稿:網友

就是一般我們用echo print 輸出字符到頁面上的時候,意味著只要執行到了echo,php就會立即輸出到客戶端,但php有幾個和緩沖相關的函數,他可以控制你輸出的行為,就是不立馬輸出,而是等你調用了ob_flush/flush函數,才輸出。

而pw就是利用了這個原理,等頁面所有的內容都生成完畢了,最后調footer()時,ob_get_contents(),獲取緩沖的內容,通過正則批量替換url,構造rewrite的url格式。

關于ob,其實有兩種主要的使用場景,一個是實現頁面壓縮輸出 - ob_gzhandler;再一個是在ajax/自定義api返回數據時,程序執行過程中,你不知道前面的程序是否有些意外的輸出字符如空格、空行等,他們在數據返回時會造成很多意外情況。

所以可以在你輸出數據前,清除前面的緩沖內容,重新開始輸出。

官方默認的重寫規則(注:重寫是web服務器 - 如apache、nginx或應用容器tomcat的功能,不是程序語言自己的功能),如pw的一條重寫規則 - apache:

RewriteRule ^(.*)-htm-(.*)$ $1.php?$2

首先,我們分析他的構成。當我們打開 global.php 文件,找到 :

<?php

$db_obstart == 1 ? ob_start('ob_gzhandler') : ob_start();

?>

我們會發現,這個全局文件打開了一個ob_start,并且進行一些判斷。這個是pw系統進行rewrite的一個關鍵。

然后我們再找到footer()函數:

<?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?', '=', '&amp;', '&', $add), array($db_dir, '-', '-', '-', ''), $url);//pw的重寫規則在這里進行字符的替換

$turl != $url && $turl .= $db_ext;

return $turl . $add;

}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 陇川县| 类乌齐县| 鸡泽县| 桃园县| 普兰店市| 和田市| 延津县| 耒阳市| 安国市| 谢通门县| 新邵县| 通榆县| 运城市| 慈利县| 嵊州市| 洞头县| 射洪县| 临高县| 桂东县| 宕昌县| 汝州市| 乌拉特前旗| 久治县| 建水县| 海安县| 牟定县| 沁源县| 丰县| 霍邱县| 浮山县| 宝鸡市| 家居| 罗源县| 洪泽县| 建平县| 孟津县| 武义县| 白城市| 青田县| 乡宁县| 高阳县|