Detecting the HTTP method or so called REQUEST METHOD can be done using the following code snippet.
$method = $_SERVER['REQUEST_METHOD']; if ($method == 'POST'){ // Method is POST } elseif ($method == 'GET'){ // Method is GET } elseif ($method == 'PUT'){ // Method is PUT } elseif ($method == 'DELETE'){ // Method is DELETE } else { // Method unknown } You could also do it using a switch if you prefer this over the if-else statement.
If a method other than GET or POST is required in an HTML form, this is often solved using a hidden field in the form.
<!-- DELETE method --> <form action='' method='POST'> <input type="hidden" name'_METHOD' value="DELETE"> </form> <!-- PUT method --> <form action='' method='POST'> <input type="hidden" name'_METHOD' value="PUT"> </form> <!-- DELETE method --> <form action='' method='POST'> <input type="hidden" name'_METHOD' value="DELETE"> </form> <!-- PUT method --> <form action='' method='POST'> <input type="hidden" name'_METHOD' value="PUT"> </form> For more information regarding HTTP methods I would like to refer to the following StackOverflow question: