How to detect if $_POST is set?

Just use it as below. because its super global so its always return true when checking for isset and empty.

<?php
    if($_POST)
    {
        echo "yes";
    }
?>

Try with:

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {}

to check if your script was POSTed.

If additional data was passed, $_POST will not be empty, otherwise it will.

You can use empty method to check if it contains data.

if ( !empty($_POST) ) {}

A simple solution may well be to just use

if (!empty($_POST))

$_POST is an array. You can check:

count($_POST)

If it is greater than zero that means some values were posted.

Tags:

Php

Post