当前位置: 移动技术网 > IT编程>开发语言>PHP > php下实现伪 url 的超简单方法[转]

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

2019年05月13日  | 移动技术网IT编程  | 我要评论
就像我的日志中的地址路径一样,让 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 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网