Is `if($_POST)` a reliable means of checking if a script has been posted?

StackOverflow https://stackoverflow.com/questions/8519428

  •  17-03-2021
  •  | 
  •  

سؤال

As per the title: is if($_POST) reliable?

Is it reliably true even if no data was posted but the HTTP POST method was used?

Is if('post' === strtolower($_SERVER['REQUEST_METHOD'])) a more reliable method, or is it overkill?

هل كانت مفيدة؟

المحلول

No.. because:

array() == false

So if no data is posted, the condition will turn out false. So check against the REQUEST_METHOD. Note that it would have taken you less time to test this, than for me to type this out.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top