Differences between QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF in php $ _ SERVER

Source: Internet
Author: User
Differences between QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF in php $ _ SERVER
This article describes the differences between QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF in the global variables $ _ SERVER in php. For more information, see.

Learn and understand the usage of the following php global variables. 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://bbs.it-home.org/(directly open the home page) 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"]: obtain the query statement. Which of the following statements can be obtained in the instance? The following value $ _ SERVER ["REQUEST_URI"] gets the value after the http://www.jbxue.com, including/$ _ SERVER ["SCRIPT_NAME"] to get the path of the current script, such as index. php $ _ SERVER ["PHP_SELF"] file name of the script currently being executed

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 helpful for correctly calling these four values in the $ _ SERVER function.

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.