Both GET and POST are methods used to send data from a client (browser) to a server. They are handled by PHP using the $_GET and $_POST superglobal variables.
GET sends data as part of the URL. This is known as a Query String. Because the data is in the URL, it is visible to everyone and has a length limit (around 2000 characters).
test_get.php?subject=PHP&web=redohub.com
<?php
echo "Study " . $_GET['subject'] . " at " . $_GET['web'];
?>
POST sends data inside the HTTP request body. It is invisible in the URL and has no size limit. It is the standard for submitting forms with passwords or large amounts of text.
<?php
echo "Hello " . $_POST['username'];
?>
| Feature | GET | POST |
|---|---|---|
| Visibility | Visible in URL | Hidden |
| Security | Low (don't use for pwd) | High |
| Bookmarks | Can be bookmarked | Cannot be bookmarked |
| Data Limit | ~2KB | No limit |
| Use Case | Retrieving data, search | Sensitive info, file uploads |
$_GET is accessible via URL parameters, so users can easily manipulate the values. Always validate and sanitize inputs.
$_REQUEST Superglobal: PHP also provides $_REQUEST, which contains the contents of both $_GET and $_POST. However, using the specific method is generally better for clarity and security.