I want to know how to detect if $_POST is set or not.
Right now I detect it like this:
if(isset($_POST['value']))
But I'm not looking if value is set anymore. Basically, any POST will work.
if(isset($_POST))
I'm not sure how PHP handle this. Perhabs isset($_POST) is always returns true since it's a PHP global?
Basically, how can I do this?
Check if $_POST Exists With isset() The isset() function is a PHP built-in function that can check if a variable is set, and not NULL. Also, it works on arrays and array-key values. PHP $_POST contains array-key values, so, isset() can work on it. To check if $_POST exists, pass it as a value to the isset() function.
In my case, when posting from HTTP to HTTPS, the $_POST comes empty. The problem was, that the form had an action like this //example.com When I fixed the URL to https://example.com , the problem disappeared. I think is something related on how the server is setup. I am having the same issues using GoDaddy as a host.
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables. The example below shows a form with an input field and a submit button.
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) ) {}
$_POST
is an array. You can check:
count($_POST)
If it is greater than zero that means some values were posted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With