Recognize and use PHP super global variables

  • 2020-03-31 20:15:31
  • OfStack

Recognize and use PHP super global variables

Super global variables, also known as predefined variables, are variables that come with PHP to make your programming easier and faster. Its types include:

$GLOBALS
Contains a reference to a valid variable within the global scope of each current script. The key of this array is the name of the global variable. The $GLOBALS array has existed since PHP 3.
$_SERVER
Variables are set by the web server or are directly associated with the execution environment of the current script. Similar to the old array
$_GET
A variable submitted to the script via a URL request.

$_POST
A variable submitted to the script via the HTTP POST method.
The $_COOKIE
Variables submitted to the script via HTTP Cookies.
$_FILES
A variable submitted to a script via an HTTP POST file upload.
$_ENV
Variables that the execution environment commits to the script.
$_REQUEST
Variables submitted to scripts via GET, POST, and COOKIE mechanisms.

The $_SESSION
The variable currently registered to the script session.

You can create a new PHP file and write the following code in the file.

 
<?php 
phpinfo(); 
?> 

Execute and you will see the following screen
< img border = 0 SRC = "http://files.jb51.net/upload/2010-1/20100126112125752.gif" border = 0 >
In this page, you can view the various types of super global variables in the system, so you can also apply it.
Here's an example of using a PHP file to display the current file and the IP address of the current server.
The code is as follows:
 
<?php 
echo " The current file is ".$_SERVER["PHP_SELF"]; 
echo "<br>"; 
echo " Current server's IP The address is: ".$_SERVER["SERVER_ADDR"]; 
?> 

Through the above example, we found that the predefined variables, or super global variables, do not need to be defined when they are used (you can query them through phpinfo), and they start with "$_", the variable names are all capital letters, and the corresponding parameters are enclosed with "[]".

This brings us to the end of our introduction to constant variables in PHP.
Michael's school is close to the final exam, so I don't think the update will be timely in the next few days. Please forgive me!

Related articles: