PHP superglobal variables
PHP Super Global Variables
Super global variables are enabled after PHP 4.1.0. They are variables that come with the PHP system and are available in all scopes of a script. .
PHP Super Global Variables
Several super global variables (superglobals) are predefined in PHP, which means This means they are available in all scopes of a script. You can use it in functions and classes without special instructions.
PHP Super Global Variable List:
· $GLOBALS
## · $_SERVER · $_REQUEST ·#· $_GET
· $_FILES
· In this chapter, we will explain several commonly used super global variables, and we will introduce the remaining variables in the next few chapters.
PHP $GLOBALS
##$GLOBALS is a super global variable group of PHP, in the entire PHP script can be accessed within the scope. $GLOBALS is a global combined array containing all variables. The name of the variable is the key of the array.The following example introduces how to use the super global variable $GLOBALS:Example
In the above example, z is a super global variable in the $GLOBALS array, which is the same Can be accessed outside the function. #PHP $_SERVER
$_SERVER is an array containing information such as header, path, and script locations. The items in this array are created by the web server. There is no guarantee that every server will offer all items; servers may ignore some, or serve items not listed here.The following example shows how to use the elements in $_SERVER:
Example
"; echo $_SERVER['SERVER_NAME']; echo "The following table lists all important elements in the $_SERVER variable:
"; echo $_SERVER['HTTP_HOST']; echo "
"; echo $_SERVER['HTTP_REFERER']; echo "
"; echo $_SERVER['HTTP_USER_AGENT']; echo "
"; echo $_SERVER['SCRIPT_NAME']; ?>
##PHP $_REQUEST
##PHP $_REQUEST is used to collect data submitted by HTML forms .The following example shows a form with an input field (input) and a submit button (submit). When a user submits form data by clicking the "Submit" button, the form data is sent to the script file specified in the action attribute of the
PHP $_POST
PHP $_POST is widely used to collect form data. Specify this attribute in the HTML form tag: "method="post".
The following example shows a form with an input field and a submit button. When the user submits form data by clicking the "Submit" button, the form data will be sent to the action attribute in the
##PHP $_GET
PHP $_GET is also widely used to collect form data. Specify this attribute in the HTML form tag: "method="get". $_GET can also collect data sent in the URL. Suppose we have a hyperlinked HTML page containing parameters:Test $GET
When the user clicks on the link "Test $GET", the parameter "subject " and "web" will be sent to "test_get.php", you can use the $_GET variable in the "test_get.php" file to get this data. The following example shows the code of the "test_get.php" file: Example