Developer
PHP
PHP TUTORIALPHP IntroductionPHP InstallationPHP Hello WorldPHP Basic SyntaxPHP VariablesPHP ConstantsPHP OutputPHP Data TypesPHP OperatorsPHP ConditionalsPHP Shorthand ConditionalsPHP LoopsPHP Loop Control StructuresPHP FunctionsPHP StringsPHP ArraysPHP Superglobal VariablesPHP in HTMLPHP RegexRegex IntroductionRegex PCRE SyntaxPHP PREG FunctionsPHP FormsPHP Forms IntroductionPHP Forms CreatingPHP Forms SecurityPHP Forms ValidationPHP Forms Required InputsPHP Forms StickyPHP Forms Advanced ValidationPHP Forms Finishing

PHP Superglobal Variables

Superglobals are built-in variables that are always available in all scopes

Can you remember we used $GLOBALS array to access globals variables inside a function in the variables chapter? We could use $GLOBALS inside a function directly because it is a superbglobal variable.

Note: All superglobal variables are available everywhere in the script.

PHP has 9 superglobals. All of them are indexed or named arrays which contains a specific set of data.

  • $GLOBALS
  • $_SERVER
  • $_GET
  • $_POST
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
  • $_REQUEST

Tip: Note that all the superglobals has an _ (underscore) after the $ (dollar sign) except $GLOBALS.

PHP has lot of elements in superglobal arrays. It's really hard to memorize all of them at once. Just understand what each superglobal variable is about. When you finish this tutorial, you will learn about elements of superglobal arrays by practice, not by studying.
Superglobal Variable Description
$GLOBALS Stores all the global scope variables.
$_SERVER Stores information about the server and execution environment.
$_GET Stores HTTP GET variables.
$_POST Stores HTTP POST variables.
$_FILES Stores HTTP file upload variables.
$_ENV Stores environment variables.
$_COOKIE Stores HTTP Cookies.
$_SESSION Stores session variables.
$_REQUEST Stores request variables ($_GET, $_POST and $_COOKIE variables).
Advertisement
0
185