PHP Beginner's Introduction to Superglobal Variables
In PHP, many predefined variables are superglobal variables, which means that they can be used within the scope of a script, and they can be accessed in functions or methods without executing global $variable;
The super global variables we will learn below
$GLOBALS$_SERVER$_REQUEST$_POST$ _GET$_FILES$_ENV$_COOKIE$_SESSION
In this chapter we will explain several commonly used Super global variables, we will introduce the other variables in the next few chapters.
1.$GLOBALS
The local variable group can be accessed in the entire scope of a PHP script.
It is a group that contains Global combined array of all variables. The name of the variable is the key of the array
2.$_SERVER
is a variable that contains information such as header, path, and script location ( script locations) and other information. The items in this array are created by the Web server.
There is no guarantee that every server will provide all items; the server may ignore some, or provide some that are not here
Listed items
"; echo $_SERVER['SERVER_NAME']; echo "
"; echo $_SERVER['HTTP_HOST']; echo "
"; echo $_SERVER['HTTP_USER_AGENT']; echo "
"; echo $_SERVER['SCRIPT_NAME']; ?>
3.$_REQUEST
$_REQUEST is used to collect data submitted by HTML forms
4.$_POST and $_GET
are widely used to obtain form data
PHP $_POST is widely used to collect form data. Specify this attribute of the HTML form tag: "method="post".
The following example displays a form with an input field (input) and a submit button (submit). When the user clicks When the "Submit" button submits the form data, the form data will be sent to the script file specified in the action attribute of the
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.
Tip: If you want to learn more about $_POST and $_GET, please visit our PHP Forms chapter