How does PHP obtain custom parameters in a url?

Source: Internet
Author: User
How does PHP obtain custom parameters in a url, such as www. xxx. comcbaindex. phpwww. xxx. comabcindex. phpwww. xxx. combbbindex. the values of php are: cbaabcbbb, namely www.xxx.com {shop} ind... how does PHP obtain custom parameters in a url,
For example:

  1. Http://www.xxx.com/ CBA /index.php
  2. Http://www.xxx.com/abc/index.php
  3. Http://www.xxx.com/bbb/index.php

The values are as follows:

  1. CBA
  2. Abc
  3. Bbb

That is
Http://www.xxx.com/?shop=/index.php
You need to obtain the shop variable.

Reply content:

How does PHP obtain custom parameters in a url,
For example:

  1. Http://www.xxx.com/ CBA /index.php
  2. Http://www.xxx.com/abc/index.php
  3. Http://www.xxx.com/bbb/index.php

The values are as follows:

  1. CBA
  2. Abc
  3. Bbb

That is
Http://www.xxx.com/?shop=/index.php
You need to obtain the shop variable.

Apache configuration like this

AliasMatch ^/(matching the regular expression of your parameter)/index. php/path/to/process. php? Arg = $1

In the process. php file, $ _ GET ['arg '] is

Tell a stupid method that has been used.
$_SERVER['PHP_SELF']Retrieve and RegEx. For more information, see the link.

In addition, PHP programs are generally written in a framework. In this case, you can go to his document to find the constant defined by him. Actually, nothing is the above.

Solution 1. Use the URI rewrite function of the server. For more information, see @ zonxin.
Solution 2. parse the URL in PHP. Note that you should use$_SERVER['REQUEST_URI']For example:

If (preg_match ('| ^/([^/] +)/index. php | ', $ _ SERVER ['request _ URI'], $ matches) {list (, $ shop) = $ matches; echo $ shop; // => the desired shop variable}

B. t. w. For the difference between REQUEST_URI and PHP_SELF, refer to this article.

. Htaccess rewrite url

isset($_SERVER['PATH_INFO'])?explode('/',my_addslashes(ltrim(trim($_SERVER['PATH_INFO']),'/')))

It can be obtained using PATH_INFO, but it is not recommended to do so. The current framework uses query_string.

Get PATH_INFO and use regular expression matching

preg_match('/\/(.*)\/index.php/',$_SERVER['PATH_INFO'],$match);var_dump($match[1]);
Related Article

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.