Home > Backend Development > PHP Tutorial > Use of PathInfo parameters in PHP_PHP tutorial

Use of PathInfo parameters in PHP_PHP tutorial

WBOY
Release: 2016-07-21 14:55:39
Original
891 people have browsed it

The global variable $_SERVER['PATH_INFO'] in PHP is a very useful parameter. Many CMS systems use this parameter when beautifying their URLs.

For the following URL:

 http://www.test.com/index.php/foo/bar.html?c=index&m=search

We can get $_SERVER['PATH_INFO'] = '/foo/bar.html', and at this time $_SERVER['QUERY_STRING'] = 'c=index&m=search';

Usually, when we first start writing PHP programs, we will use URLs such as: http://www.test.com/index.php?c=search&m=main. This kind of URL not only looks very strange, but also It is also very unfriendly to search engines. Many search engines will ignore the content after the Query String when indexing. Although Google will not ignore the Query String, it will give a relatively high PR value to other pages that do not contain the Query String.

The following is a very simple code to parse PATH_INFO:

以下为引用的内容:

if( !isset( $_SERVER['PATH_INFO'] ) ){
$pathinfo = 'default';
}else{
$pathinfo = explode('/', $_SERVER['PATH_INFO']);
}

if( is_array($pathinfo) AND !empty($pathinfo) ){
$page = $pathinfo[1];
}else{
$page = 'a.php';
}

require "$page.php";

//帮客之家 LieHuo.NeT
?>

The following is the quoted content:

if( !isset( $_SERVER['PATH_INFO'] ) ){
$pathinfo = 'default';
}else{
$pathinfo = explode('/', $_SERVER['PATH_INFO']);
}

if( is_array($pathinfo) AND !empty($pathinfo) ){
$page = $pathinfo[1];
}else{
$page = ' a.php';
}

require "$page.php";

//Bang Ke Home LieHuo.NeT
?>

http://www.bkjia.com/PHPjc/364348.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364348.htmlTechArticle
The global variable $_SERVER['PATH_INFO'] in PHP is a very useful parameter, many CMS systems This parameter is used when beautifying your own URL. For the following URL: h...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template