Home >Backend Development >PHP Tutorial >In php $_SERVER, the difference between QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF
This article introduces the differences between QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF in the global variable $_SERVER in PHP. Friends in need can refer to it.
Learn and understand the usage of the following PHP global variables. 1.$_SERVER["QUERY_STRING"] Description: Query string 2,$_SERVER["REQUEST_URI"] Description: URI required to access this page 3,$_SERVER["SCRIPT_NAME"] Description: Contains the path of the current script 4,$_SERVER["PHP_SELF"] Description: The file name of the currently executing script Example: 1. http://bbs.it-home.org/ (open the homepage directly) result: $_SERVER["QUERY_STRING"] = "" $_SERVER["REQUEST_URI"] = "/" $_SERVER["SCRIPT_NAME"] = "/index.php" $_SERVER["PHP_SELF"] = "/index.php"2, http://www.jbxue.com/?p=222 (with query) result: $_SERVER["QUERY_STRING"] = "p=222" $_SERVER["REQUEST_URI"] = "/?p=222" $_SERVER["SCRIPT_NAME"] = "/index.php" $_SERVER["PHP_SELF"] = "/index.php"3, http://www.jbxue.com/index.php?p=222&q=jbxue result: $_SERVER["QUERY_STRING"] = "p=222&q=jbxue" $_SERVER["REQUEST_URI"] = "/index.php?p=222&q= jbxue" $_SERVER["SCRIPT_NAME"] = "/index.php" $_SERVER["PHP_SELF"] = "/index.php"$_SERVER["QUERY_STRING"] obtains the query statement. As can be seen from the example, the value after ? is obtained. $_SERVER["REQUEST_URI"] Get the value after http://www.jbxue.com, including / $_SERVER["SCRIPT_NAME"] gets 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'] Summary: For QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF, an in-depth understanding is beneficial to correctly calling these four values in the $_SERVER function. |