Forms and Superglobals
PHP receives form data in $_GET (from the URL) and $_POST (from the request body). $_SERVER describes the request. Always validate input and escape output with htmlspecialchars to prevent cross site scripting. The example simulates a submitted form.
Example
$_POST = ["name" => "<b>Ada</b>", "age" => "21"];
$name = trim($_POST["name"] ?? "");
$age = filter_var($_POST["age"] ?? "", FILTER_VALIDATE_INT);
echo htmlspecialchars($name), "\n";
var_dump($age);
var_dump(filter_var("not-an-email", FILTER_VALIDATE_EMAIL));Result
<b>Ada</b> int(21) bool(false)
Exercise
Make text safe to show in HTML.
echo ($name);
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.