Skip to content

Chapter 13 of 38

Superglobals

Use request, server, session, cookie, environment, file, and global arrays safely.

36 minutes 10 quick checksBy Subha Prasad
Lesson 13 of 38Course navigation

Lesson content

Read, practise, then check your understanding

Superglobals include $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, $_ENV, $_SESSION, $_REQUEST, and $GLOBALS. Availability does not imply trust.

Practical example

<?php
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, ['options' => ['default' => 1, 'min_range' => 1]]);
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';

Copy validated values into named domain inputs rather than passing superglobals through the application. Avoid $_REQUEST because it hides provenance. Proxy headers, filenames, environment values, and cookies require explicit trust/configuration rules.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes $_GET?
Which PHP term matches this description: Query-string input parsed into an array.
Which statement best describes $_POST?
Which PHP term matches this description: Parsed form body data for supported content types.
Which statement best describes $_SERVER?
Which PHP term matches this description: Request and server execution metadata.
Which statement best describes $_SESSION?
Which PHP term matches this description: Server-side session state available after session initialization.
Which statement best describes $_COOKIE?
Which PHP term matches this description: Cookie values supplied by the client and therefore untrusted.

0 of 10 checks passed

Your progress is saved on this device.