The $ _ SERVER function is often used in the process of writing a program. Sometimes it may cause a great misunderstanding if you do not know much about the variables. Today, I have found several small examples to illustrate the usage of the four commonly used variables ~~ The $ _ SERVER function is often used in the process of writing a program. Sometimes it may cause a great misunderstanding if you do not know much about the variables. Today, I have found several small examples to illustrate the usage of the four commonly used variables ~~
Script ec (2); script
$ _ SERVER stores information about the current SERVER, which has the following values:
The Code is as follows: |
|
$ _ SERVER ["QUERY_STRING"], $ _ SERVER ["REQUEST_URI"], $ _ SERVER ["SCRIPT_NAME"], $ _ SERVER ["PHP_SELF"] |
The following describes the differences between QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF variables in the $ _ SERVER function, it is easy to obtain the required values in practical applications for your reference.
1, $ _ SERVER ["QUERY_STRING"]
Description: query string
2, $ _ SERVER ["REQUEST_URI"]
Description: The URI required to access this page
3, $ _ SERVER ["SCRIPT_NAME"]
Description: path containing the current script
4, $ _ SERVER ["PHP_SELF"]
Description: File Name of the script being executed
Instance:
1, http://ask.mbatrip.com (Open home)
Result:
The Code is as follows: |
|
$ _ SERVER ["QUERY_STRING"] = "" $ _ SERVER ["REQUEST_URI"] = "/" $ _ SERVER ["SCRIPT_NAME"] = "/index. php" $ _ SERVER ["PHP_SELF"] = "/index. php" 2, http://ask.mbatrip.com /? Tags/upload (with query) |
Result:
The Code is as follows: |
|
$ _ SERVER ["QUERY_STRING"] = "tags/upload ″ $ _ SERVER ["REQUEST_URI"] = "/? Tags/upload ″ $ _ SERVER ["SCRIPT_NAME"] = "/index. php" $ _ SERVER ["PHP_SELF"] = "/index. php" 3, http://ask.mbatrip.com /? Tags/upload/2 |
Result:
$ _ SERVER ["QUERY_STRING"] = "tags/upload/2"
$ _ SERVER ["REQUEST_URI"] = "/index. php? Tags/upload/2"
$ _ 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? Value after
$ _ SERVER ["REQUEST_URI"] gets the value after the http://www.111cn.net, including/
$ _ SERVER ["SCRIPT_NAME"] obtains the path of the current script, for example, index. php.
$ _ SERVER ["PHP_SELF"] File Name of the script currently being executed
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.