PHP obtains the complete URL path and physical path. The predefined variable $ _ SERVER of PHP is an array containing headers, path information, and script location. the entity of the array is created by the web SERVER. using the $ _ SERVER array, we can obtain the predefined variable $ _ SERVER of PHP after URL completion. it is an array containing headers, path information, and script location, the object of the array is created by the web server.
Using the $ _ SERVER array, we can obtain the complete URL path and actual path, so that we can use them as we like.
$ _ SERVER ['server _ name'] // NAME of the host on which the script is currently running.
$ _ SERVER [SERVER_PORT '] // port used by the user to connect to the SERVER.
$ _ SERVER ['request _ URI '] // The request url except the host name of the currently running script.
$ _ SERVER ['document _ root'] // ROOT directory of the DOCUMENT where the script is currently running.
Example URL: http://www.cndong.cn/Test/Test.php
$ _ SERVER ['server _ name']: www.cndong.cn
$ _ SERVER ['server _ port']: 80www.2cto.com
$ _ SERVER ['request _ URI ']:/Test. php
$ _ SERVER ['document _ root']:/home/var/www/cndong.cn/htdocs
Therefore, the complete URL path is "http: //". $ _ SERVER ['server _ name']. $ _ SERVER ['request _ URI '].
Note:
1. the default http PORT is 80. Therefore, $ _ SERVER ['server _ port'] is not included in the complete URL path. of course, this is a special case!
2. someone will use $ _ SERVER ['remote _ host'] to obtain the HOST name, but it means that the HOST name of the user is browsing the current page (this variable must be created by the Web SERVER ).
Extension:
$ _ SERVER ['remote _ host ']
Modify the HostnameLookups in the httpd. conf configuration file of the apache server
Author: Xu Xiujun
Outputs (headers), an array of path information and script location. the array entity is created by the web SERVER. with the $ _ SERVER array, we can get the URL...