PHP 8 Beginner Forms · 1 min read

Detect GET vs POST in PHP

Start the PHP 8 learning path »

❮ PHP 8 Home All Tutorials ❯

How do I know which HTTP method was used?

$_SERVER['REQUEST_METHOD'].

Example

PHP 8 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.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…