0PricingLogin
PHP Academy · Lesson

GET vs POST: When to Use Each

Understand the difference between HTTP GET and POST in PHP.

HTTP Methods in Web PHP

When a browser submits an HTML form, it uses either the GET or POST HTTP method. PHP captures the submitted data via superglobals:

  • $_GET — data appended to the URL
  • $_POST — data in the request body

GET Method

GET appends form data as query string parameters to the URL:

<!-- HTML form -->
<form method="GET" action="search.php">
    <input name="query" type="text">
    <button type="submit">Search</button>
</form>

<!-- URL becomes: search.php?query=php+tutorial -->

<?php
$q = $_GET['query'] ?? '';
echo 'You searched for: ' . htmlspecialchars($q);

All lessons in this course

  1. GET vs POST: When to Use Each
  2. Reading Form Data with Superglobals
  3. Input Validation Techniques
  4. Sanitizing User Input
← Back to PHP Academy