Thuta Learning
IntermediateProgrammingbeginner

$_GET & $_POST

Relax. We'll talk through this in plain words — no textbook voice.

$_GET and $_POST are commonly used to receive form data. GET sends data through the URL query string, making it a good fit for search, filters, and shareable links. POST sends data in the request body, making it a better fit for logins, contact forms, and create/update actions.

php
<?php
// Example URL: search.php?keyword=php
$keyword = $_GET["keyword"] ?? "";

if ($keyword !== "") {
  echo "You searched for: " . htmlspecialchars($keyword);
} else {
  echo "Please type a search keyword.";
}
?>
You should see
If the URL includes ?keyword=php, it will display You searched for: php.

Easy traps

  • Outputting user input without escaping it can open the door to an XSS vulnerability.
$_GET & $_POST | Thuta Learning