The Super global variable is enabled after PHP 4.1.0 and is a self-contained variable in the PHP system and is available in all scopes of a script.
Several super global variables (superglobals) are predefined in php, which means they are available in all scopes of a script. You don't need to specify it, you can use it in functions and classes.
PHP Super Global Variables List:
- $GLOBALS
- $_server
- $_request
- $_post
- $_get
- $_files
- $_env
- $_cookie
- $_session
PHP $GLOBALS
$GLOBALS is a super global variable group of PHP that can be accessed in all scopes of a PHP script.
$GLOBALS is a globally combined array that contains all the Variables. The name of the variable is the key of the Array.
The following example shows how to use the Super global variable $GLOBALS:
<? $x =$y =$GLOBALS$GLOBALS $GLOBALS[' y 'echo$z; ?>
In the example above, Z is a super global variable in an $globals array that can also be accessed outside the Function.
PHP $_server
$_server is an array of information, such as header information (header), path, and script location (scripts locations), and so On. The items in this array are created by the Web server. There is no guarantee that each server will provide all the items, the server may ignore some, or provide some items that are not listed Here.
The following example shows how to use the elements in $_server:
<?PHPEcho $_server[' php_self ']; The file name of the current execution scriptEcho"<br>";Echo $_server[' server_name ']; Get host nameEcho"<br>";Echo $_server[' Http_host ']; Ibid .Echo"<br>";Echo $_server[' Http_referer ']; Gets the URL of the current pageEcho"<br>";Echo $_server[' Http_user_agent ']; Get browser-related InformationEcho"<br>";Echo $_server[' Script_name ']; The file name of the current execution script
?>
The following table lists the important elements in all $_server variables:
Element/code |
Description |
$_server[' php_self '] |
The file name of the current execution script, which is related to document Root. For example, using $_server[' php_self ' in a script with an address of Http://example.com/test.php/foo.bar will get/test.php/foo.bar. The __FILE__ constant contains the full path and file name of the current (for example, the Containing) file. Starting with PHP 4.3.0, if PHP is running in command-line mode, this variable will contain the script Name. Previous versions of this variable are not available. |
$_server[' Gateway_interface '] |
The version of the CGI specification used by the server; for example, "cgi/1.1". |
$_server[' server_addr '] |
The IP address of the server where the script is currently Running. |
$_server[' server_name '] |
The host name of the server where the script is currently Running. If the script is running on a virtual host, the name is determined by the value set by that virtual Host. (eg: Www.runoob.com) |
$_server[' Server_software '] |
The server identification string, given in the header information in response to the Request. (eg: apache/2.2.24) |
$_server[' Server_protocol '] |
The name and version of the communication protocol when the page is Requested. For example, "http/1.0". |
$_server[' Request_method '] |
Access the request method used by the page; for example, "GET", "HEAD", "POST", "PUT". |
$_server[' Request_time '] |
Timestamp at the start of the Request. Available from PHP 5.1.0. (eg: 1377687496) |
$_server[' query_string '] |
Query string, if any, for page access. |
$_server[' http_accept '] |
Accept: the contents of the item, if any, in the current request Header. |
$_server[' Http_accept_charset '] |
Accept-charset in the current request header: the contents of the item, if one exists. For Example: "iso-8859-1,*,utf-8". |
$_server[' Http_host '] |
Host in current request header: the contents of the item, if one exists. |
$_server[' Http_referer '] |
The address, if any, that directs the User's agent to the previous page of the current Page. Determined by the user agent Settings. Not all user agents will set the item, and some also provide the ability to modify the Http_referer. In short, the value is not trustworthy. ) |
$_server[' HTTPS '] |
If the script is accessed through the HTTPS protocol, it is set to a non-null Value. |
$_server[' REMOTE_ADDR '] |
The IP address of the user who browsed the current Page. |
$_server[' Remote_host '] |
The host name of the user who browsed the current Page. DNS reverse resolution is not dependent on the User's Remote_addr. |
$_server[' Remote_port '] |
The port number used by the User's machine to connect to the Web server. |
$_server[' Script_filename '] |
The absolute path of the current execution script. |
$_server[' Server_admin '] |
This value indicates the Server_admin parameter in the Apache server configuration File. If the script is running on a virtual host, the value is the value of that virtual Host. (such as: [email Protected]) |
$_server[' Server_port '] |
The port used by the Web server. The default value is "80". If SSL secured connection is used, This value is the HTTP port set by the User. |
$_server[' server_signature '] |
A string that contains the server version and the virtual host Name. |
$_server[' path_translated '] |
The base path of the file system (not the document Root) where the current script Resides. This is the result of the server making a Virtual-to-real-path image. |
$_server[' Script_name '] |
Contains the path to the current Script. This is useful when the page needs to point to itself. The __FILE__ constant contains the full path and file name of the current script, such as the containing File. |
$_server[' Script_uri '] |
The URI is used to specify the page to be Accessed. For example, "/index.html". |
PHP $_request
PHP $_request is used to collect data submitted by HTML Forms.
The following example shows a form (form) of an input field and a Submit button (submit). When the user submits the form data by clicking the "submit" button, the form data is sent to the script file specified in the Action property in the <form> tab. In this example, we specify the file to process the form Data. If you want other PHP files to handle this data, you can modify the specified script file Name. We can then use the Super global variable $_request to collect input field data from the Form:
$_server [' php_self '];? > ">Name: <input type=" text "name=" fname "><input type=" Submit "></form><? $name$_request[' fname 'echo$name? ></body >
PHP Super Global variables