Obtain the summary of the current url path and server path (obtain the server path from the url)

Source: Internet
Author: User
: This article mainly introduces how to obtain the current url path and server path by PH (obtain the server path of the current path by url). If you are interested in the PHP Tutorial, refer to it. The following are some of the information. I hope to help you with the small knowledge of getting paths in php!

1, $ _ SERVER ["QUERY_STRING"] description: query string 2, $ _ SERVER ["REQUEST_URI"] description: URI3, $ _ SERVER ["SCRIPT_NAME"] description: Path 4 containing the current script, $ _ SERVER ["PHP_SELF"] description: file name of the script being executed

  

Demo: 1
Http://www.xxx.com/(directly open the home page) results: $ _ SERVER ["QUERY_STRING"] = "" $ _ SERVER ["REQUEST_URI"] = "/" $ _ SERVER ["SCRIPT_NAME"] = "/index. php "$ _ SERVER [" PHP_SELF "] ="/index. php"

Demo: 2
Http://www.xxx.com /? P = 1 (with query) result: $ _ SERVER ["QUERY_STRING"] = "p = 1" $ _ SERVER ["REQUEST_URI"] = "/? P = 1 "$ _ SERVER [" SCRIPT_NAME "] ="/index. php "$ _ SERVER [" PHP_SELF "] ="/index. php"

Demo 3
Http://www.xxx.com/index.php? P = 1 & q = xxx result: $ _ SERVER ["QUERY_STRING"] = "p = 1 & q = xxx" $ _ SERVER ["REQUEST_URI"] = "/index. php? P = 1 & q = xxx "$ _ SERVER [" SCRIPT_NAME "] ="/index. php "$ _ SERVER [" PHP_SELF "] ="/index. php"

$ _ SERVER ["QUERY_STRING"]: obtain the query statement. Which of the following statements can be obtained in the instance? The following value $ _ SERVER ["REQUEST_URI"] gets the value after the http://www.xxx.com, including/$ _ SERVER ["SCRIPT_NAME"] to get the path of the current script, such as index. php $ _ SERVER ["PHP_SELF"] file name of the script currently being executed

Current url: "http: //". $ _ SERVER ['http _ host']. $ _ SERVER ['php _ SELF ']

To sum up, for QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF, an in-depth understanding will help us call these four values correctly in the $ _ SERVER function. Explain the differences between the four variables in the $ _ SERVER function: QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF.

$ _ SERVER ["REQUEST_URI"]: get the complete [except domain name] url of the current request

The sorting is slightly unknown. please point out...

The preceding section describes how to obtain the current url path and server path by using PH (obtain the server path of the current path by using url), including the following content. if you are interested in the PHP Tutorial, you can help.

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.