Superglobals are special variables that PHP creates for you. They are available everywhere: inside functions, classes and files, with no global keyword.
Each one is an array, and each one answers a question about the current request.
| Superglobal | What it holds |
|---|---|
$_GET | Data in the URL, like ?page=2 |
$_POST | Data sent from a form with method="post" |
$_REQUEST | $_GET, $_POST and cookies together (avoid) |
$_SERVER | Information about the server and the request |
$_SESSION | Data stored for one visitor between page loads |
$_COOKIE | Cookies the browser sent |
$_FILES | Files uploaded with a form |
$_ENV | Environment variables |
$GLOBALS | All global variables |
A quick example
Suppose someone opens index.php?name=Ravi. PHP puts name into $_GET for you.
<?php
// URL: index.php?name=Ravi
echo "Hello, " . htmlspecialchars($_GET["name"]);
Hello, Ravi
You did not have to read the URL yourself. PHP did it.
Why superglobals matter
They are how PHP receives everything from the outside world: forms, links, cookies, uploads. That is also why they are dangerous. All the data in these arrays comes from the visitor, so it must be treated as untrusted. The chapters on forms and security show how to handle it safely.
You will learn each one properly in the superglobals chapter.
Do not write to superglobals carelessly
$_GET and $_POST is normal. Changing them ($_GET["id"] = 5;) makes code very hard to follow. Copy the value into your own variable instead.