← CodePrimer
PHP Beginner Forms

Detect GET vs POST in PHP

How do I know which HTTP method was used?

$_SERVER['REQUEST_METHOD'].

Sample
<?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

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share