php下实现伪 url 的超简单方法[转]

前端之家收集整理的这篇文章主要介绍了php下实现伪 url 的超简单方法[转]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

就像我的日志中的地址路径一样,让index.PHP?action=one&do=two
变成:?index/action/one/do/two
<div class="codetitle"><a style="CURSOR: pointer" data="22471" class="copybut" id="copybut22471" onclick="doCopy('code22471')"> 代码如下:

<div class="codebody" id="code22471">
index.PHP
--------------
<?PHP //PARSINGQUERYSTRING
$QS=explode("&",$_SERVER['QUERY_STRING']);
$QS=explode('/',$QS[0]); //IFModulisUndefinedsetittoindex
if(!$QS[0])$MODUL='index';
else$MODUL=strtolower($QS[0]); //WEcanmakeaVariable$_QUERY
//foralternative_GET
for($i=1;$i<count($QS);$i+=2)
{
$_QUERY[$NVAR]=$NVAR=$QS[$i];
$$NVAR=$QS[$i+1];
} //ChecktheModulisexists?
if(!file_exists("modul_directory/{$MODUL}.PHP"))
$MODUL="index"; ####THISISEXAMPLETOIMPLEMENTATIONTHESCRIPT
//LoadTheTemplate
include("template.PHP");
//LoadTheModule
include("modul_directory/{$MODUL}.PHP");
//LoadTheFooter
include("footer.PHP"); ?> wecanaccessthemodulinURLlikethis:
================================= www.example.com/?forum/topic/20
-itmeanloadthemodulforum.PHP,andsetthe_QUERY['topic']=20 www.foo.com/?voting/id/54/type/piechart&choice=2
-itmeanloadthemodulvoting.PHP,andsetthe_QUERY['id']=54and_QUERY['type']='piechart'andset_GET['choice']=2

原文链接:https://www.f2er.com/php/29841.html

猜你在找的PHP相关文章