About the Magic constants of PHP

Source: Internet
Author: User
$_server stores current server information, with several values such as $_server["Query_string"],$_server["Request_uri"],$_server["Script_name" and $_server[" Php_self "] often easy to confuse, the following through the example of the $_server function in the query_string,request_uri,script_name and php_self variable differences, master the relationship between the four, It is convenient to obtain the required value correctly in practical application for reference.
1,$_server["Query_string"]
Description: A string that queries (query)
2,$_server["Request_uri"]
Description: The 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
Instance:
1,http://www.biuuu.com/(open homepage directly)
Results:
$_server["query_string"] = ""
$_server["Request_uri"] = "/"
$_server["script_name"] = "/index.php"
$_server["php_self"] = "/index.php"
2,http://www.biuuu.com/?p=222 (with inquiry)
Results:
$_server["query_string"] = "p=222"
$_server["Request_uri"] = "/?p=222"
$_server["script_name"] = "/index.php"
$_server["php_self"] = "/index.php"
3,http://www.biuuu.com/index.php?p=222&q=biuuu
Results:
$_server["query_string"] = "p=222&q=biuuu"
$_server["Request_uri"] = "/index.php?p=222&q=biuuu"
$_server["script_name"] = "/index.php"
$_server["php_self"] = "/index.php"
$_server["Query_string"] gets the query statement, in the instance, gets the following value
$_server["Request_uri"] gets the value after http://www.biuuu.com, including/
$_server["Script_name"] gets the path to the current script, such as: index.php
$_server["Php_self"] The file name of the script that is currently executing
To summarize, for Query_string,request_uri,script_name and php_self, deep understanding will help us to correctly invoke these four values in the $_server function. The differences between the four variables are mastered by Query_string,request_uri,script_name and php_self in the $_server function by example.
  • 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.