PHP - detecting request type (GET, POST, PUT or DELETE)

Discuss coding issues, and scripts related to PHP and MySQL.
MarPlo
Posts:186

PHP - detecting request type (GET, POST, PUT or DELETE)

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

Admin Posts:805
Simple use $_SERVER['REQUEST_METHOD'].

Code: Select all

$request = $_SERVER['REQUEST_METHOD'];
echo $request;

if($request === 'GET') {
  // ...
}
else if($request === 'POST') {
  // ...
}
else if($request === 'PUT') {
  // ...
}
else if($request === 'DELETE') {
  //  ...
} 

Similar Topics