PHP – Detect HTTP Request Type

You can detect the HTTP Request Type using the following variable.

  • $_SERVER[‘REQUEST_METHOD’]

 

Use the following PHP to handle different HTTP Request.

<?php
  $request_method = $_SERVER['REQUEST_METHOD'];

  switch($request_method) {
    case 'PUT':
    case 'DELETE':
      // Ignore the PUT and DELETE request =P
      return;
    case 'GET':
      // GET request received
      break;
    case 'POST':
      // POST request received
      break;
  }
?>

 

Done =)

Reference: StackOverflow – PHP detecting request type (GET, POST, PUT or DELETE)

2 thoughts on “PHP – Detect HTTP Request Type”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.