Skip to content

Instantly share code, notes, and snippets.

@joshuamorse
Created December 19, 2012 21:23
Show Gist options
  • Save joshuamorse/4340645 to your computer and use it in GitHub Desktop.
Save joshuamorse/4340645 to your computer and use it in GitHub Desktop.
A Request Mirror Script in PHP
<?php
/**
* A simple script that acts as a request mirror.
* It will return a JSON object containing all sorts of information
* relating to the request it received.
*/
$url = 'http://';
if (isset($_SERVER['HTTPS'])) {
$url = 'https://';
}
$url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
if ($_SERVER['QUERY_STRING']) {
$url .= "?{$_SERVER['QUERY_STRING']}";
}
$request = array(
'body' => file_get_contents('php://input'),
'headers' => getallheaders(),
'origin' => $_SERVER['REMOTE_ADDR'],
'method' => $_SERVER['REQUEST_METHOD'],
'params' => array(
'get' => $_GET,
'post' => $_POST,
),
'url' => $url,
);
header('Content-Type: application/json');
die(json_encode($request));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment