: 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.