<?php

// Simple Web Service Debug Code.

// Usage: To use this code, add it to a page and set that page
// as the 'HTTP URL: (Requires Fully Qualified)' property 
// of a HTTP Request item. 

// Call your web service. The output of this script will
// be added to your servers syslog, which is typically:

// Mac OS: /var/log/system.log
// Linux: /var/log/messages

// View messages in realtime with:

// tail -f /var/log/messages

// See more: http://php.net/manual/en/function.syslog.php


//--------------------------------------------------------
// Start Code
//--------------------------------------------------------


// POST
syslog(LOG_NOTICE, print_r($_POST, true));

// FILES
syslog(LOG_NOTICE, print_r($_FILES, true));

// STREAM - For JSON And Other NON-POST Requests.
syslog(LOG_NOTICE, stream_get_contents(fopen("php://input", 'r+' )));

// Print Request Headers
syslog(LOG_NOTICE, print_r(getallheaders(), true) );


$json_raw = file_get_contents("php://input");

echo '<h3>RAW JSON FROM REQUEST</h3>' . $json_raw;

$c = json_decode($json_raw);

echo '<h3>stdClass From FROM REQUEST</h3>';

var_dump($c);


/**
 * Utility
 */

if (!function_exists('getallheaders'))
{
  function getallheaders()
  {
    $headers = '';
    foreach ($_SERVER as $name => $value)
    {
      if (substr($name, 0, 5) == 'HTTP_')
      {
        $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
      }
    }
    return $headers;
  }
}

?>