Understanding and using PHP super global variables

Source: Internet
Author: User

Understanding and using PHP super global variables

Super global variables are also called pre-defined variables. They are self-contained variables in the PHP system. They make your program design more convenient and convenient. Its types include:

$ GLOBALS
Contains a reference to a variable that is valid globally for each current script. The key name of the array is the name of the global variable. $ GLOBALS array exists from PHP 3.
$ _ SERVER
Variables are set by the web server or directly associated with the execution environment of the current script. Similar to the old Array
$ _ GET
Variables submitted to the script through URL requests.

$ _ POST
Variables submitted to the script through the http post method.
$ _ COOKIE
Variables submitted to the script through HTTP Cookies.
$ _ FILES
Variables submitted to the script by uploading the http post file.
$ _ ENV
Variables submitted to the script in the execution environment.
$ _ REQUEST
Variables submitted to the script through GET, POST, and COOKIE mechanisms.

$ _ SESSION
The variable currently registered to the script session.

The specific information is not explained here. You can create a PHP file and write the following code in the file.

Copy codeThe Code is as follows:
<? Php
Phpinfo ();
?>

And then you can see the following picture

On this page, you can view various types of super global variables in the system and apply them.
The following example shows how to use a PHP file to display the current file and the IP address of the current server.
The Code is as follows:
Copy codeThe Code is as follows:
<? Php
Echo "the current file is". $ _ SERVER ["PHP_SELF"];
Echo "<br> ";
Echo "the IP address of the current SERVER is:". $ _ SERVER ["SERVER_ADDR"];
?>

Through the above example, we found that the pre-defined variable, that is, the super global variable, does not need to be defined during use (you can use phpinfo to query) and starts with "$, the variable names are all uppercase letters, and the corresponding parameters are enclosed in.

At this point, we will end the introduction of constant variables in PHP.
Magio's school is approaching the final exam, and it is estimated that the updates in the next few days will not be too timely. Sorry!

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.