Web Analytics

PHP Superglobals Overview

Intermediate~30 min read

Superglobals are built-in arrays that are always accessible from any scope. They provide access to request data, server information, sessions, and more!

Output
Click Run to execute your code

All Superglobals

Superglobal Purpose
$_GET URL parameters
$_POST Form data (POST method)
$_SERVER Server and environment info
$_SESSION Session variables
$_COOKIE Cookie values
$_FILES Uploaded files
$_REQUEST GET, POST, and COOKIE combined
$_ENV Environment variables
$GLOBALS All global variables

$_SERVER Examples

<?php
echo $_SERVER['SERVER_NAME'];    // Domain name
echo $_SERVER['REQUEST_METHOD']; // GET, POST, etc.
echo $_SERVER['SCRIPT_NAME'];    // Current script path
echo $_SERVER['REMOTE_ADDR'];    // Client IP address
?>

Summary

  • Superglobals: Always accessible
  • $_GET: URL parameters
  • $_POST: Form data
  • $_SERVER: Server info
  • No global keyword needed

What's Next?

Next, learn about GET & POST - handling form submissions and URL parameters!