Thuta Learning
IntermediateProgrammingbeginner

Superglobals Intro

Relax. We'll talk through this in plain words — no textbook voice.

Superglobals are built-in PHP variables you can access from anywhere in your script. $_SERVER, $_GET, $_POST, $_SESSION, $_COOKIE are essential for building web apps.

php
<?php
echo "Current script: " . $_SERVER["PHP_SELF"] . "<br>";
echo "Server name: " . $_SERVER["SERVER_NAME"] . "<br>";
echo "Request method: " . $_SERVER["REQUEST_METHOD"];
?>
You should see
The browser will display the current script, server name, and request method.

Easy traps

  • Don't blindly trust values like $_SERVER['HTTP_HOST'] — validate them whenever they feed into security-sensitive logic.
Superglobals Intro | Thuta Learning