PHP Super globals

The superglobals are available throughout your script. Superglobals include form data sent from your visitor, cookie data, session information, local server information, and more.

PHP superglobal

There are nine superglobal arrays available shown in the following table.

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

Several predefined variables in PHP are "superglobals", which means they are available in all scopes throughout a script. There is no need to do global $variable; to access them within functions or methods.

Variable Meaning
$_GET Contains all variables sent via a HTTP GET request. For example, a URL of myfile.php?name=Paul would load myfile.php and give you $_GET["name"] with the value "name".
$_POST Contains all variables sent via a HTTP POST request.
$_FILES Contains all variables sent via a HTTP POST file upload.
$_COOKIE Contains all variables sent via HTTP cookies.
$_REQUEST Contains all variables sent via HTTP GET, HTTP POST, and HTTP cookies. This is the equivalent of combining $_GET, $_POST, and $_COOKIE.
$_SESSION Contains all variables stored in a user's session.
$_SERVER Contains all variables set by the web server.
$_ENV Contains all environment variables.
$GLOBALS An array containing all global variables in your script.

 Note : By default, all of the superglobals are available but there
	       are directives that affect this availability. For further information, refer to the
	        documentation for variables_order. 

 Note: Dealing with register_globals
          If the deprecated register_globals directive is set to on then the variables 
          within will also be made available in the global scope of the script. For example,
           $_POST['foo'] would also exist as $foo. 

 Note: Variable variables
          Superglobals cannot be used as variable variables inside functions or class methods. 

Key value for $_ENV and $_SERVER

The most commonly used $_SERVER variables are shown in the following table. Only PHP_SELF is available on the command line.

Name Value
HTTP_REFERER If the user clicked a link to get the current page, this will contain the URL of the previous page, or it will be empty if the user entered the URL directly.
HTTP_USER_AGENT The name reported by the visitor's web browser.
PATH_INFO Any data passed in the URL after the script name.
PHP_SELF The name of the current script.
QUERY_STRING Includes everything after the question mark in a GET request. Not available on the command line.

Example - Use $_SERVER

HTTP_REFERER and HTTP_USER_AGENT can find out a lot about your visitor and then take the appropriate action.

				        if (isset($_SERVER['HTTP_REFERER'])) { 
				                print "The page you were on previously was {$_SERVER['HTTP_REFERER']}<br />"; 
				        } else { 
				                print "You didn't click any links to get here<br />"; 
				<a href="refer.php">Click me!</a>

The PATH_INFO element in $_SERVER allows you to grab directory information specified after the script. Consider this script:

					if (isset($_SERVER['PATH_INFO'])) { 
					        print "The page you requested was {$_SERVER['PATH_INFO']}<br />"; 
					} else { 
					        print "You didn't request a page<br />"; 

PHP Tutorials






Echo and Print Statement

Data Types



Number Convert

PHP String

php variable substitution in string

php string element

php string function

php addcslashes function

php addslashes function

php get magic quotes gpc function

php get meta tags function

php urlencode function

PHP $ and $$ Variables

PHP constant

PHP Magic Constants

PHP Static Variable

PHP Super Globals

PHP Globals

PHP Server

PHP reserved variable get

PHP reserved variable post

PHP reserved variable FILES

PHP reserved variable Cookies

PHP reserved variable Session

PHP reserved variable Request

PHP reserved variable environment

PHP Operator

PHP Arithmetic Operator

PHP Comparison Operator

PHP Incrementing and Decrementing Operators

PHP Identical Operators

PHP Logical Operators

PHP String Operators

PHP Ternary Operators

PHP Execution Operators

PHP Operator Precedence

PHP Array Operator

PHP Class

PHP Class Inheritance

PHP constructor and destructor

PHP abstract class

PHP class access control

PHP statement

PHP If statement

PHP else statement

PHP else if statement

PHP control structure statement

PHP while loop

PHP do while loop

PHP for loop

PHP for each loop

PHP break statement

PHP continue statement

PHP declare statement

PHP return statement

PHP require statement

PHP include

PHP require once

PHP include once

PHP goto statement

PHP function

PHP function parameter

PHP function scope

PHP array

PHP array operator

PHP array element loop

PHP array foreach loop

PHP array multidimensional

PHP html forms

PHP get and post method

form redirect

file inclusion