欢迎来到福编程网,本站提供各种互联网专业知识!

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

发布时间:2007-09-24 作者: 来源:转载
就像我的日志中的地址路径一样,让index.php?action=one&do=two变成:?index/action/one/do/two复制代码代码如下:index.php--------------wecanaccessthemodulinURLlikethis:=================================www.example.com/?forum/topic/20-itmeanloadthemo
就像我的日志中的地址路径一样,让index.php?action=one&do=two
变成:?index/action/one/do/two
复制代码 代码如下:
index.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

相关推荐