Detecting request type in PHP (GET, POST, PUT or DELETE)

前端 未结 13 1458
不思量自难忘°
不思量自难忘° 2020-11-22 08:02

How can I detect which request type was used (GET, POST, PUT or DELETE) in PHP?

13条回答
  •  情话喂你
    2020-11-22 08:18

    By using

    $_SERVER['REQUEST_METHOD']
    

    Example

    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         // The request is using the POST method
    }
    

    For more details please see the documentation for the $_SERVER variable.

提交回复
热议问题