PHP › Constants & Superglobals
What are PHP superglobals, and what are some of the most commonly used ones?
BeginnerAnswer
Superglobals are built in PHP variables that are always accessible from any scope throughout a script, including inside functions and classes, without needing to explicitly declare them as global, and commonly used superglobals include $_GET and $_POST for accessing submitted form or URL data, $_SESSION for accessing session data, $_SERVER for accessing information about the current request and server environment, and $_FILES for accessing uploaded file information.
echo $_SERVER['REQUEST_METHOD'];
$username = $_POST['username'] ?? '';Real-world example A login form reads the submitted username and password directly from the $_POST superglobal after the form is submitted, without needing to pass that data through any additional function parameters.