PHP中的$_SERVER['PATH_INFO']
2013-04-23 11:54
309 查看
PHP中的$_SERVER['PATH_INFO']
PHP中的全局变量$_SERVER['PATH_INFO']是一个很有用的参数,众多的CMS系统在美化自己的URL的时候,都用到了这个参数。对于下面这个网址:
http://www.test.com/index.php/foo/bar.html?c=index&m=search
我们可以得到 $_SERVER['PATH_INFO'] = ‘/foo/bar.html’,而此时
$_SERVER['QUERY_STRING'] = 'c=index&m=search';
通 常,我们最初开始PHP程序编写的时候,都会使用诸如: http://www.test.com/index.php?c=search&m=main 这样的URL,这种URL不仅看起来非常奇怪,而且对于搜索引擎也是非常不友好的。很多搜索引擎收录的时候,都会忽略Query String之后的内容,google虽然不会忽略Query String,但是对于其他不含Query String的页面,会给于比较高的PR值。
下面是一段解析PATH_INFO的非常简单的代码:
<?php
if( !isset( $_SERVER['PATH_INFO'] ) ){
$pathinfo = 'default';
}else{
$pathinfo = explode('/', $_SERVER['PATH_INFO']);
}
if( is_array($pathinfo) &&
!empty($pathinfo) ){
$page = $pathinfo[1];
}else{
$page = 'a.php';
}
require "$page.php";
?>
相关文章推荐
- PHP中的$_SERVER['PATH_INFO']
- PHP中的$_SERVER['PATH_INFO']
- PHP中的$_SERVER['PATH_INFO']
- php.ini文件中的include_path设置和$_SERVER['DOCUMENT_ROOT']
- php中遇到include_path='.;C:\php5\pear'的错误
- PHP中__FILE__和$_SERVER['PHP_SELF']的不同点
- php通过$_SERVER['HTTP_USER_AGENT']获取浏览器相关参数(转)
- php $_SERVER['PHP_SELF'] $_SERVER['SCRIPT_NAME'] $_SERVER['REQUEST_URI']区别
- PHP获取当前url路径的函数及服务器变量:$_SERVER['.....']
- PHP获取当前域名$_SERVER['HTTP_HOST']和$_SERVER['SERVER_NAME']的区别
- Centos下安装apache,php Can't connect to MySQL server on 'server' (13)
- PHP $_SERVER['PHP_SELF']、$_SERVER['SCRIPT_NAME'] 与 $_SERVER['REQUEST_URI'] 之间的区别
- $_SERVER['PHP_SELF']漏洞知多少
- Server Error in '/' Application. Access to the Path Is Denied" error message appears
- PHP Storm Built In Server Doesn't Recognize mod_rewrite
- Nginx+php-fpm SSL不输出$_SERVER['HTTPS']的解决办法
- php几个预定义变量$_SERVER['DOCUMENT_ROOT']
- Zend Server提示Error: Could not locate a free PHP process from the "application/x-httpd-php" pool within the 'Connection Timeout'.
- Warning: phpinfo() [function.phpinfo]: It is not safe to rely on the system's timezone settings.
- apache php $_SERVER['SERVER_NAME']没有保存端口号的问题(解决)