Variables called superglobal are very important in PHP programming. These so-called superglobal variables are the built-in variables in PHP, each of which having individual scopes. These are predefined variables available in the script and can be accessed within functions or methods from any position inside a code and be used to read from or write to the core PHP structures.


The $GLOBALS superglobal refers to all the global variables that can be accessed within a function. 

Example of $GLOBALS

    $var1 = 1;
    $var2 = 2;
    function multiply()
        $GLOBALS['x'] = $GLOBALS['var1'] * $GLOBALS['var2'];
    echo $x;


The $_SERVER superglobal is used to hold the information of a specified server such as path, headers and script location.

Example of $_SERVER

   echo $SERVER['server_name'];


The $_GET superglobal gets the name of the server or variable.

Example of $_GET

   echo "Your name is: " . $_GET['name'];


The $_POST superglobal posts the name of the server or variable.

Example of $_POST

   echo "Your age is: " . $_POST['age'];


The $_FILES superglobal uploads a file to a server.


The $_COOKIE superglobal is small piece of information or data sent from a website and store it in the user’s web browser.

Example of $_COOKIE

   echo "Your name is saved as: " . $_COOKIE['saved_name'];


The $_SESSION superglobal is a way to store information in a variable or array to be used across multiple pages. The information is not stored in the user’s computer.

Example of $_SESSION

    $_SESSION['users_name'] = "Robert";
    $users_name = "Newman";
    echo $_SESSION['users_name'];


The $_REQUEST superglobal is used to request a value of a variable. 


The $_ENV superglobal is an environment variable. These variables are imported into PHP’s global namespace from the environment under which the PHP parser is running. 

Example of $_ENV

   echo "Your username is: " . $_ENV['username'];


›› go to examples ››