Created
December 19, 2012 21:23
-
-
Save joshuamorse/4340645 to your computer and use it in GitHub Desktop.
A Request Mirror Script in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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