php下實(shí)現(xiàn)偽 url 的超簡(jiǎn)單方法[轉(zhuǎn)]
更新時(shí)間:2007年09月24日 11:41:47 作者:
就像我的日志中的地址路徑一樣,讓 index.php?action=one&do=two
變成: ?index/action/one/do/two
index.php
--------------
<?php
// PARSING QUERY STRING
$QS=explode("&",$_SERVER['QUERY_STRING']);
$QS=explode('/',$QS[0]);
// IF Modul is Undefined set it to index
if (!$QS[0]) $MODUL='index';
else $MODUL=strtolower($QS[0]);
// WE can make a Variable $_QUERY
// for alternative _GET
for ($i=1;$i<count($QS);$i+=2)
{
$_QUERY[$NVAR]=$NVAR=$QS[$i];
$$NVAR=$QS[$i+1];
}
// Check the Modul is exists?
if (!file_exists("modul_directory/{ $MODUL }.php"))
$MODUL="index";
#### THIS IS EXAMPLE TO IMPLEMENTATION THE SCRIPT
// Load The Template
include("template.php");
// Load The Module
include("modul_directory/{ $MODUL }.php");
// Load The Footer
include("footer.php");
?>
we can access the modul in URL like this:
=================================
www.example.com/?forum/topic/20
- it mean load the modul forum.php, and set the _QUERY['topic']=20
www.foo.com/?voting/id/54/type/piechart&choice=2
- it mean load the modul voting.php, and set the _QUERY['id']=54 and _QUERY['type']='piechart' and set _GET['choice']=2
變成: ?index/action/one/do/two
復(fù)制代碼 代碼如下:
index.php
--------------
<?php
// PARSING QUERY STRING
$QS=explode("&",$_SERVER['QUERY_STRING']);
$QS=explode('/',$QS[0]);
// IF Modul is Undefined set it to index
if (!$QS[0]) $MODUL='index';
else $MODUL=strtolower($QS[0]);
// WE can make a Variable $_QUERY
// for alternative _GET
for ($i=1;$i<count($QS);$i+=2)
{
$_QUERY[$NVAR]=$NVAR=$QS[$i];
$$NVAR=$QS[$i+1];
}
// Check the Modul is exists?
if (!file_exists("modul_directory/{ $MODUL }.php"))
$MODUL="index";
#### THIS IS EXAMPLE TO IMPLEMENTATION THE SCRIPT
// Load The Template
include("template.php");
// Load The Module
include("modul_directory/{ $MODUL }.php");
// Load The Footer
include("footer.php");
?>
we can access the modul in URL like this:
=================================
www.example.com/?forum/topic/20
- it mean load the modul forum.php, and set the _QUERY['topic']=20
www.foo.com/?voting/id/54/type/piechart&choice=2
- it mean load the modul voting.php, and set the _QUERY['id']=54 and _QUERY['type']='piechart' and set _GET['choice']=2
相關(guān)文章
ThinkPHP3.2.1圖片驗(yàn)證碼實(shí)現(xiàn)方法
這篇文章主要介紹了ThinkPHP3.2.1圖片驗(yàn)證碼實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了thinkPHP3.2.1生成圖片驗(yàn)證碼過程中遇到的問題及相應(yīng)的解決方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08YII動(dòng)態(tài)模型(動(dòng)態(tài)表名)支持分析
這篇文章主要介紹了YII動(dòng)態(tài)模型(動(dòng)態(tài)表名)支持,分析了動(dòng)態(tài)模型的原理并結(jié)合實(shí)例形式給出了相關(guān)使用方法,需要的朋友可以參考下2016-03-03laravel yajra插件 datatable的使用詳解
這篇文章主要介紹了laravel yajra插件 datatable的使用詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01laravel 配置路由 api和web定義的路由的區(qū)別詳解
今天小編就為大家分享一篇laravel 配置路由 api和web定義的路由的區(qū)別詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-09-09tp5.1框架數(shù)據(jù)庫(kù)子查詢操作實(shí)例分析
這篇文章主要介紹了tp5.1框架數(shù)據(jù)庫(kù)子查詢操作,結(jié)合實(shí)例形式分析了tp5.1框架數(shù)據(jù)庫(kù)子查詢相關(guān)原理、操作實(shí)現(xiàn)方法與注意事項(xiàng),需要的朋友可以參考下2020-05-05PHP生成圖片驗(yàn)證碼、點(diǎn)擊切換實(shí)例
這篇文章主要介紹了PHP生成圖片驗(yàn)證碼實(shí)例,同時(shí)介紹了點(diǎn)擊切換(看不清?換一張)效果實(shí)現(xiàn)方法,需要的朋友可以參考下2014-06-06