您好,登錄后才能下訂單哦!
這篇文章給大家介紹PHP中偽靜態(tài)技術(shù)的原理是什么,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
inj.php:
<?php set_time_limit(10); $id=$_GET["id"]; $id=str_replace(" ","%20",$id); $id=str_replace("=","%3D",$id); $url="http://www.xxx.com/index.php/library/more/id/$id.html"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,"$url"); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//啟用時(shí)將curl_init()獲取的信息以文件流的形式返回,而不是直接輸出 curl_setopt($ch,CURLOPT_HEADER,0);//啟用時(shí)會(huì)將頭文件的信息作為數(shù)據(jù)流輸出 $output=curl_exec($ch); curl_close($ch); print_r($output); ?>
用wamp搭建一個(gè)服務(wù)器,把上面inj.php放到wamp/www/中,然后在Havij中跑 http://127.0.0.1/inj.php?id=1
=============================
PHP偽靜態(tài)實(shí)現(xiàn)方法一(利用Apache 服務(wù)器的功能)
1、檢查Apache是否支持mod_rewrite
2、讓Apache 支持.htaccess
3、建立.htaccess文件
4、規(guī)則:
RewriteEngine on
RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$index.php?action=$1&id=$2
([a-zA-Z]{1,})-([0-9]{1,}) 是 URL長啥樣
$1 是([a-zA-Z]{1,}) 所匹配的
$2 是[0-9]{1,} 所匹配的
比如說:www.xx.com/page-18.html
真實(shí)的URL如下:
action = page
id = 18
============================
PHP偽靜態(tài)實(shí)現(xiàn)方法二(編碼實(shí)現(xiàn))
$Php2Html_FileUrl = $_SERVER["REQUEST_URI"]
echo $Php2Html_FileUrl
例子:// localhost/php100/test.php?id|1@action|2
$Php2Html_UrlString = str_replace("?","",str_replace("/","",strrchr(strrchr($Php2Html_FileUrl,"/"),"?")) )) /* 內(nèi)層的strrchr出來:/test.php?id|1@action|2 外層的strrchr出來:id|1@action|2 內(nèi)層的str_replace出來:把 / 號(hào)去掉,本例子 沒有 外層的str_replace出來:把 ?號(hào)去掉,本例子 沒有 */ $Php2Html_UrlQueryStrList = explode("@",$Php2Html_UrlString); /*把str變成以@為界限劃分的數(shù)組:id|1 和 action|2*/ foreach($Php2Html_UrlQueryStrList as $Php2Html_UrlQueryStr) { $Php2Html_TmpArray = explode("|",$Php2Html_UrlQueryStr); /* id => 1 和 action => 2*/ $_GET[$Php2Html_TmpArray[0]] = $Php2Html_TmpArray[1]; }
============================
PHP偽靜態(tài)實(shí)現(xiàn)方法三(編碼實(shí)現(xiàn))
例子: localhost/php100/test.php/1/2
$filename = basename($_SERVER["SCRIPT_NAME"]); echo $_SERVER["SCRIPT_NAME"]; echo $filename; if(strtolower($filename) == 'test.php'){ if(!empty($_GET[id])){ $id=intval($_GET[id]); echo $id; $action = intval($_GET[action]); echo $action; }else{ $nav=$_SERVER["REQUEST_URI"]; $script=$_SERVER["SRCIPT_NAME"]; //這句話應(yīng)該是把URL前面那段給搞掉。。剩下 "1/2"之類的。。 $nav=ereg_replace("$script","",urldecode($nav)); echo $nav; $vars = explode("/",$nav); print_r($vars); $id=intval($vars[1]); $action=intval($vars[2]); } echo $id.'&'.$action; }
============================
PHP偽靜態(tài)實(shí)現(xiàn)方法四(編碼實(shí)現(xiàn))
function mod_rewrite(){ global $_GET; $nav = $_SERVER["REQUEST_URI"]; $script_name = $_SERVER["SCRIPT_NAME"] $nav=substr(ereg_replace("$script_name"),"",urldecode($nav)),1); $nav=preg_replace("/^.ht(m){1}(l){0,1}$/","",$nav);//去掉尾部的htm或html $vars=explode("/",$nav); print_r($vars); for($i=0;$i<count($vars);$i+=2) { $_GET[$vars[$i]] = $vars[$i+1]; } return $_GET; }
============================
PHP偽靜態(tài)實(shí)現(xiàn)方法五(編碼實(shí)現(xiàn))
例子:/1,100,8630.html
if(preg_match(“/\/(\d+),(\d+),(\d+)\.html/si”,$path_info,$arr_path)){ $gid =intval($arr_path[1]); //取得值1 $sid =intval($arr_path[2]); //取得值100 $softid =intval($arr_path[3]); //取得值8630 } else echo "Path:Error!";
總結(jié)下:
(1)偽靜態(tài)技術(shù)比較好突破,需要自己構(gòu)造中轉(zhuǎn)注入頁面。
(2)偽靜態(tài)技術(shù)原理都很簡單,就是把原來的 index.php?id=1 這種形式的URL給替換成其它形式。
關(guān)于PHP中偽靜態(tài)技術(shù)的原理是什么就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。