How to detect if $_POST is set?

前端 未结 6 1769
时光说笑
时光说笑 2020-12-09 08:31

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 lo

6条回答
  •  无人及你
    2020-12-09 08:58

    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) ) {}
    

提交回复
热议问题