For detecting request type in PHP we can use variable $_SERVER by using $_SERVER[‘REQUEST_METHOD’]. $_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. Following methods can be detected with key ‘REQUEST_METHOD’:
- GET
- POST
- PUT
- DELETE
Example:
[php]
if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’) {
// The request is using the POST method
}
[/php]