PHP: getting the complete URL path and physical path _ PHP Tutorial

Source: Internet
Author: User
Tags server array
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...

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.