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

UnkwnTech picture UnkwnTech · Dec 11, 2008 · Viewed 460.2k times · Source

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

Answer

gnud picture gnud · Dec 11, 2008

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.