codegurukool.com · Free coding tutorials & online compiler

Home › PHP Tutorial › PHP superglobals and form handling

PHP superglobals and form handling

Read what the visitor submitted.

Superglobals such as $_GET, $_POST, $_SERVER and $_SESSION are available everywhere. Always clean user input with htmlspecialchars before printing it, to prevent XSS attacks. The example fills $_POST by hand because there is no real form here.

Example code

<?php
$_POST["name"] = "<b>Ada</b>";   // pretend a form sent this
$name = htmlspecialchars($_POST["name"] ?? "guest");
echo "Hello, " . $name;
?>

Run this code in the online editor

← PHP arraysPHP date and time →