PathInfo in PHP

Source: Internet
Author: User
The global variable $ _ SERVER ['path _ info'] in PathInfo PHP in PHP is a very useful parameter. when many CMS systems beautify their URLs, this parameter is used.

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 ', in this case, $ _ SERVER ['query _ string'] = 'C = index & m = search ';

Usually, when we first started writing PHP programs, we would use http://www.test.com/index.php? C = search & m = main. this kind of URL is not only strange, but also unfriendly to search engines. When indexed by many search engines, the content after Query String is ignored. Although google does not ignore Query String, other pages without Query String are given a relatively high PR value.

The following is a simple code for parsing 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 ";

?>



References:
1. PHP Parse Pathinfo
2. CPAN PathInfo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.