Created
August 28, 2015 12:52
-
-
Save wowo/791bddbfa896e3566e95 to your computer and use it in GitHub Desktop.
Simple api to capture and test API callbacks
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 | |
$log = __DIR__ . '/api.log'; | |
if ('POST' == $_SERVER['REQUEST_METHOD']) { | |
$payload = json_decode(file_get_contents('php://input'), true) ?: $_POST; | |
file_put_contents( | |
$log, | |
sprintf( | |
"[%s] (%s - %s) %s\n", | |
(new \DateTime())->format('Y-m-d H:i:s'), | |
$_SERVER['REMOTE_ADDR'], | |
gethostbyaddr($_SERVER['REMOTE_ADDR']), | |
var_export($payload, 1) | |
), | |
FILE_APPEND | |
); | |
exit('OK' . PHP_EOL); | |
} else { | |
if (file_exists($log)) { | |
echo '<pre>' . file_get_contents($log); | |
} else { | |
echo 'No log file under ' . $log; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment