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)

Advertisements

2 thoughts on “PHP – Detect HTTP Request Type”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s