Usage of QUERY_STRING and REQUEST_URI in php $ _ SERVER

Source: Internet
Author: User
The use of QUERY_STRING and REQUEST_URI in php $ _ SERVER often uses the $ _ SERVER function in the process of writing a program. sometimes, variables that are not familiar with will cause a great misunderstanding, today I have found several small examples to illustrate the usage of the four variables that are commonly used.

$ _ SERVER stores information about the current SERVER, which has the following values:

$ _ 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 convenient 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, the code is as follows:

$ _ SERVER ["QUERY_STRING"] = ""

$ _ SERVER ["REQUEST_URI"] = "/"

$ _ SERVER ["SCRIPT_NAME"] = "/index. php"

$ _ SERVER ["PHP_SELF"] = "/index. php"

Instance 2, 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"

Instance 3, the code is as follows:

$ _ 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.phpfensi.com, 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. the QUERY_STRING function in the $ _ SERVER function is explained through an instance, REQUEST_URI, SCRIPT_NAME, and PHP_SELF determine the differences between the four variables.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.