>  기사  >  백엔드 개발  >  php下实现伪 url 的超简单方法[转]_PHP教程

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

WBOY
WBOY원래의
2016-07-21 15:54:51875검색

就像我的日志中的地址路径一样,让 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 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/318416.htmlTechArticle就像我的日志中的地址路径一样,让index.php?action=onenbsp; 变成:?index/action/one/do/two 复制代码 代码如下: index.php -------------- ?php //PARSINGQUERYSTRING...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.