The following are some of the ways to get the path in php A little knowledge, hope it helps you!
1,$_SERVER["QUERY_STRING"] 说明:查询(query)的字符串 2,$_SERVER["REQUEST_URI"] 说明:访问此页面所需的URI 3,$_SERVER["SCRIPT_NAME"] 说明:包含当前脚本的路径 4,$_SERVER["PHP_SELF"] 说明:当前正在执行脚本的文件名
demo: 1
http://www.xxx.com/(Open the homepage directly) Result: $_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"] gets the query statement. It can be seen from the example that the value after ? is obtained. $_SERVER["REQUEST_URI"] obtains the value after http://www.xxx.com, including / $_SERVER ["SCRIPT_NAME"] Get the path of the current script, such as: index.php $_SERVER["PHP_SELF"] The file name of the currently executing script
Current url: "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']
To summarize, for QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF, an in-depth understanding will help us correctly call these four values in the $_SERVER function. Learn the differences between the four variables QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF in the $_SERVER function through detailed examples.
$_SERVER["REQUEST_URI"]: Get the complete URL of the current request [except domain name]
The arrangement is slightly unclear, please point out...