PHP Superglobals
Superglobals are built-in PHP variables that are always accessible in every scope — inside functions, classes, and files — without needing to use the global keyword. They provide access to form data, server information, cookies and more.
Common superglobals include $_GET, $_POST, $_SERVER, $_SESSION, $_COOKIE, $_FILES, and $_REQUEST, each holding a different category of data related to the current request.
$_GET["key"];
$_POST["key"];
$_SERVER["key"];Common superglobals
$_GET and $_POST hold form data sent via GET or POST requests. $_SERVER holds information about headers, paths and script locations. $_SESSION and $_COOKIE store persistent data between requests.
Why superglobals matter
Because superglobals are automatically available everywhere, you never need to pass them explicitly into functions to access request or server data.
<?php
echo $_SERVER["PHP_SELF"];
?>/index.php$_SERVER["PHP_SELF"] returns the path of the currently executing script.
<?php
// Assume URL is page.php?name=Amy
echo $_GET["name"];
?>Amy$_GET reads query string parameters passed in the URL.
Key points
- Superglobals are available in every scope without special declaration.
- $_GET and $_POST hold submitted form data.
- $_SERVER holds request and server environment information.
- $_SESSION and $_COOKIE store data across multiple requests.
