php -S 0.0.0.0:3001 postbin.php
Last active
May 18, 2018 19:40
-
-
Save kohenkatz/cbb5cbf49b3f4382dc0bc83dcc2d2f93 to your computer and use it in GitHub Desktop.
"PostBin" is a simple server that logs all requests to files in TEMP. Partially based on https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
This file contains hidden or 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 | |
function getHeaderList() { | |
$headerList = []; | |
foreach ($_SERVER as $name => $value) { | |
if (preg_match('/^HTTP_/',$name)) { | |
// convert HTTP_HEADER_NAME to Header-Name | |
$name = strtr(substr($name,5),'_',' '); | |
$name = ucwords(strtolower($name)); | |
$name = strtr($name,' ','-'); | |
// add to list | |
$headerList[$name] = $value; | |
} | |
} | |
return $headerList; | |
} | |
// IMPORTANT NOTE: This filename format limits you to a single request per second. | |
// If multiple requests come in a single second, THEY WILL OVERWRITE EACH OTHER. | |
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'postbin-' . date('Ymdhis') . '.txt'; | |
$handle = fopen($filename, 'w'); | |
$data = sprintf( | |
"%s %s %s" . PHP_EOL, | |
$_SERVER['REQUEST_METHOD'], | |
$_SERVER['REQUEST_URI'], | |
$_SERVER['SERVER_PROTOCOL'] | |
); | |
fwrite($handle, $data); | |
foreach (getHeaderList() as $name => $value) { | |
fwrite($handle, $name . ': ' . $value . PHP_EOL); | |
} | |
fwrite($handle, PHP_EOL); | |
fwrite($handle, file_get_contents('php://input')); | |
fclose($handle); | |
header('X-Filepath: ' . $filename); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment