PathInfo in PHP

Source: Internet
Author: User
The global variable $_server[' path_info ' in PHP is a useful parameter, and 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 use URLs like Http://www.test.com/index.php?c=search&m=main, which not only look very strange, And it's also very unfriendly to search engines. Many search engines ingest, will ignore the content after query string, although Google will not ignore query string, but for other pages without query string, will give a higher PR value.

Here is a very 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";

?>



Resources:
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.