php下实现伪 url 的超简单方法[转]_PHP教程
程序员文章站
2024-02-15 22:43:28
...
就像我的日志中的地址路径一样,让 index.php?action=one&do=two
变成: ?index/action/one/do/two
index.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{
$_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
复制代码 代码如下:
index.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
$_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
上一篇: 如果获取循环内的值解决办法
推荐阅读
-
php下实现伪 url 的超简单方法[转]_PHP教程
-
escape unescape的php下的实现方法_PHP教程
-
php简单实现数组分页的方法,php数组分页_PHP教程
-
Linux环境下php实现给网站截图的方法,linuxphp_PHP教程
-
thinkPHP删除前弹出确认框的简单实现方法,thinkphp弹出_PHP教程
-
用windows下编译过的eAccelerator for PHP 5.1.6实现php加速的使用方法_PHP教程
-
PHP简单的伪静态URL机制实现
-
PHP实现多维数组转字符串和多维数组转一维数组的方法,多维维数_PHP教程
-
thinkPHP3.2简单实现文件上传的方法,_PHP教程
-
PHP下escape解码函数的实现方法_PHP教程