Home > Backend Development > PHP Tutorial > Define global variables Understand and use PHP super global variables

Define global variables Understand and use PHP super global variables

WBOY
Release: 2016-07-29 08:41:46
Original
944 people have browsed it

Understand and use PHP super global variables
Super global variables are also called predefined variables. They are variables that come with the PHP system. They can make your programming more convenient and faster. Its types include:
$GLOBALS
Contains a reference to each variable that is valid in the global scope of the current script. The key names of this array are the names of global variables. The $GLOBALS array exists since 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 via URL requests.
$_POST
Variables submitted to the script via the HTTP POST method.
$_COOKIE
Variable submitted to the script via the HTTP Cookies method.
$_FILES
Variables submitted to the script via HTTP POST file upload.
$_ENV
Variables submitted by the execution environment to the script.
$_REQUEST
Variables submitted to the script via GET, POST and COOKIE mechanisms.
$_SESSION
The variable currently registered for the script session.
The specific information will not be explained one by one here. You can create a new PHP file and write the following code in the file.

Copy the code The code is as follows:


phpinfo();
?>


and execute it, you can see the following screen
 认识并使用PHP超级全局变量
In this page, you will You can view various types of super global variables that exist in the system, so you can also apply them.
The following is 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:

Copy the code The code is as follows:


echo "The current file is ".$_SERVER["PHP_SELF"];
echo "
";
echo " The IP address of the current server is: ".$_SERVER["SERVER_ADDR"];
?>


Through the above example, we found that predefined variables, that is, super global variables, do not need to be defined when using them (you can go through phpinfo query), and starts with "$_", the variable names are all capital letters, and the corresponding parameters are enclosed with "[ ]".
At this point, our introduction to constant variables in PHP is over.
McGe’s school is approaching its final exams, so updates in the next few days may not be timely. I hope you will forgive me!

The above introduces how to define global variables, understand and use PHP super global variables, including the content of defining global variables. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template