PHP Global Variables-Super global variables
Many of the predefined variables in PHP are "hyper-global", which means they are available in all scopes of a script. There is no need to perform a global $variable in a function or method; You can access them.
These hyper-global variables are:
- $GLOBALS
- $_server
- $_request
- $_post
- $_get
- $_files
- $_env
- $_cookie
- $_session
$GLOBALS-Referencing all variables available in the global scope
$GLOBALS This global variable is used anywhere in the PHP script to access global variables (from functions or methods).
PHP stores all global variables in an array named $GLOBALS [index]. The name of the variable is the key of the array.
The following example shows how to use the Super global variable $GLOBALS:
<?php $x = 75; $y = 25; function addition () { $GLOBALS [' z '] = $GLOBALS [' x '] + $GLOBALS [' Y ']; addition (); Echo $z;?>
In the above example, because Z is a variable in the $GLOBALS array, it can also be accessed outside of the function.
PHP $_server
$_server This hyper-global variable holds information about the header, path, and location of the script.
The following example shows how to use some of the elements in $_server:
<?php echo $_server[' php_self '];echo "<br>", echo $_server[' server_name '];echo "<br>"; Echo $_server[' Http_host '];echo ' <br> '; Echo $_server[' http_referer '];echo ' <br> '; Echo $_server[' http_user_agent ']; echo "<br>"; Echo $_server[' script_name ');? >
/lianxi/mysql.php
Www.1223.com
Www.1223.com
http://www.1223.com/lianxi/
mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/54.0.2840.99 safari/537.36
/lianxi/mysql.php
127.0.0.1
PHP Global Variables-Super global variables