Super global variables in PHP are built-in variables that are available in all scopes—inside functions, classes, and files—without requiring global keyword. They allow PHP scripts to access server data, form data, session data, cookies, and environment variables easily.
These variables play a major role in handling forms, sessions, server requests, and more.
List of Super Global Variables in PHP
PHP provides nine superglobal arrays:
$GLOBALS$_SERVER$_REQUEST$_POST$_GET$_FILES$_ENV$_COOKIE$_SESSION
Let’s understand each.
1. $GLOBALS
Used to access global variables from anywhere.
$x = 10;
function test() {
echo $GLOBALS['x']; // 10
}
test();
2. $_SERVER
Contains information about the server, headers, and script paths.
echo $_SERVER['PHP_SELF']; // current file name
echo $_SERVER['SERVER_NAME']; // server name
echo $_SERVER['REQUEST_METHOD']; // GET or POST
3. $_REQUEST
Contains data from both GET and POST requests (and cookies).
$name = $_REQUEST['username'];
⚠ Not recommended for sensitive data.
4. $_POST
Collects form data sent using POST method.
echo $_POST['email'];
5. $_GET
Collects data sent in URL query.
echo $_GET['id']; // from URL ?id=10
6. $_FILES
Used for handling file uploads.
print_r($_FILES['photo']);
7. $_ENV
Stores environment variables.
echo $_ENV['PATH'];
8. $_COOKIE
Stores and retrieves cookie values.
echo $_COOKIE['user'];
9. $_SESSION
Used to store session data across multiple pages.
session_start();
echo $_SESSION['username'];
Why Superglobals Are Important?
✔ Available everywhere without declaring
✔ Essential for form handling
✔ Manage sessions, cookies, and file uploads
✔ Provide server and environment information
✔ Improve communication between PHP and browser
Conclusion
Super global variables form the backbone of PHP programming.
Whether you’re collecting form data, uploading files, tracking users with sessions, or accessing server information—superglobals make it all possible.
Citations
🔗 View other articles about PHP:
http://savanka.com/category/learn/php/
🔗 External PHP Documentation:
https://www.php.net/manual/en/