Codectionary / Developer documentation / PHP

PHP Request Data

PHP exposes HTTP request data through superglobal arrays such as $_GET and $_POST. Data from a request is untrusted and should be validated before use.

Syntax

$query = $_GET["q"] ?? "";
$clean = trim($query);

Examples

Reading an optional query value

A small, runnable example of this syntax.

<?php
$query = $_GET["q"] ?? "";
$query = trim($query);

if ($query !== "") {
  echo htmlspecialchars($query, ENT_QUOTES, "UTF-8");
}
?>

Best practices

  • Validate input for its expected shape and escape output for its destination; never treat request data as safe by default.
  • Keep examples small while learning, then combine the idea with a real project.

Runtime & versions

PHP runtime on a server or CLI. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

PHP Manual

Specifications & further reading