php下实现伪 url 的超简单方法[转]
2018-09-07 11:56
就像我的日志中的地址路径一样,让index.php?action=one&do=two
变成:?index/action/one/do/two
复制代码 代码如下:
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:
=================================
-itmeanloadthemodulforum.php,andsetthe_QUERY[topic]=20
-itmeanloadthemodulvoting.php,andsetthe_QUERY[id]=54and_QUERY[type]=piechartandset_GET[choice]=2
文章标题:php下实现伪 url 的超简单方法[转]
文章链接:http://soscw.com/index.php/essay/11378.html