Home  >  Article  >  Backend Development  >  In php $_SERVER, the difference between QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF

In php $_SERVER, the difference between QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF

WBOY
WBOYOriginal
2016-07-25 08:57:18829browse
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.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn