Skip to main content
Replace automatic PHP syntax highlighting with HTML one
Source Link
Benjamin Loison
  • 5.8k
  • 4
  • 20
  • 37

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:

HTTP protocol's PUT and DELETE and their usage in PHP

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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

1. added a semicolon `$method = $_SERVER['REQUEST_METHOD'];` 2. added spaces between `else if`
Source Link
mujuonly
  • 11.9k
  • 5
  • 48
  • 81

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 } else ifelseif ($method == 'GET'){ // Method is GET } else ifelseif ($method == 'PUT'){ // Method is PUT } else ifelseif ($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 htmlHTML form, this is often solved using ana 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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

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 } else if ($method == 'GET'){ // Method is GET } else if ($method == 'PUT'){ // Method is PUT } else if ($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 an 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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

1. added a semicolon `$method = $_SERVER['REQUEST_METHOD'];` 2. added spaces between `else if`
Source Link

Detecting the HTTP method or so called REQUEST METHOD can be done using the following code snippet.

$method = $_SERVER['REQUEST_METHOD']$_SERVER['REQUEST_METHOD']; if ($method == 'POST') { // Method is POST } elseifelse if ($method == 'GET') { // Method is GET } elseifelse if ($method == 'PUT') { // Method is PUT } elseifelse if ($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 an 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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

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 an 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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

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 } else if ($method == 'GET'){ // Method is GET } else if ($method == 'PUT'){ // Method is PUT } else if ($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 an 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> 

For more information regarding HTTP methods I would like to refer to the following StackOverflow question:

HTTP protocol's PUT and DELETE and their usage in PHP

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
Loading
Improved answer for future visitors.
Source Link
Peter
  • 9.2k
  • 8
  • 69
  • 100
Loading
Source Link
Peter
  • 9.2k
  • 8
  • 69
  • 100
Loading