Skip to content

PHP Tutorial Variables and Constants

Superglobals Overview

Lesson 31 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

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.

SuperglobalWhat it holds
$_GETData in the URL, like ?page=2
$_POSTData sent from a form with method="post"
$_REQUEST$_GET, $_POST and cookies together (avoid)
$_SERVERInformation about the server and the request
$_SESSIONData stored for one visitor between page loads
$_COOKIECookies the browser sent
$_FILESFiles uploaded with a form
$_ENVEnvironment variables
$GLOBALSAll global variables

A quick example

Suppose someone opens index.php?name=Ravi. PHP puts name into $_GET for you.

index.php
PHP
<?php
// URL: index.php?name=Ravi
echo "Hello, " . htmlspecialchars($_GET["name"]);
Output
OUTPUT
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.

warning
Do not write to superglobals carelessly
Reading $_GET and $_POST is normal. Changing them ($_GET["id"] = 5;) makes code very hard to follow. Copy the value into your own variable instead.