Page 1 of 1

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

Posted: 11 Jan 2015, 10:59
by MarPlo
How can I detect which request type was used (GET, POST, PUT or DELETE) in a php script?

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

Posted: 11 Jan 2015, 11:01
by Admin
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') {
  //  ...
}