Skip to content

Instantly share code, notes, and snippets.

@DKepov
Last active December 7, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DKepov/bff8c0b8ce9e1f07c97b968cfd91f186 to your computer and use it in GitHub Desktop.
Save DKepov/bff8c0b8ce9e1f07c97b968cfd91f186 to your computer and use it in GitHub Desktop.
logRequest.php
<?php
function logRequest($targetFile)
{
$headerList = [];
foreach ($_SERVER as $name => $value) {
if (0 === strpos($name, 'HTTP_')) {
$name = str_replace('_', ' ', substr($name, 5));
$name = ucwords(strtolower($name));
$name = str_replace(' ', '-', $name);
$headerList[ $name ] = $value;
}
}
$data = sprintf("%s %s %s\n", $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER['SERVER_PROTOCOL']);
foreach ($headerList as $name => $value) {
$data .= $name . ': ' . $value . "\n";
}
$data .= "\n";
file_put_contents($targetFile, $data . file_get_contents('php://input') . "\n");
}
@DKepov
Copy link
Author

DKepov commented Dec 7, 2019

logRequest('/tmp/post-' . time() . '.log');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment