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:
- Http://www.xxx.com/ CBA /index.php
- Http://www.xxx.com/abc/index.php
- Http://www.xxx.com/bbb/index.php
The values are as follows:
- CBA
- Abc
- 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:
- Http://www.xxx.com/ CBA /index.php
- Http://www.xxx.com/abc/index.php
- Http://www.xxx.com/bbb/index.php
The values are as follows:
- CBA
- Abc
- 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]);