← CodePrimer
PHP
Beginner
Forms
Detect GET vs POST in PHP
How do I know which HTTP method was used?
$_SERVER['REQUEST_METHOD'].
<?php
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
if ($method === 'POST') {
// handle submit
}
Notes
Useful when the same .php file shows and processes a form.
Keywords: REQUEST_METHOD · get · post
Related
PHP
Embed PHP inside HTML
How do I mix PHP and HTML?
PHP
PHP comments
How do I write comments in PHP?
PHP
PHP variable rules
What are the rules for PHP variables?
PHP
echo vs print
Should I use echo or print?
PHP
PHP scalar data types
What data types does PHP have?
JavaScript
Live input event
How do I react as the user types?