PHP 8
Beginner
Forms
· 1 min read
Detect GET vs POST in PHP
How do I know which HTTP method was used?
$_SERVER['REQUEST_METHOD'].
Example
<?php
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
if ($method === 'POST') {
// handle submit
}
Line-by-Line Walkthrough
Useful when the same .php file shows and processes a form.