Skip to content

Instantly share code, notes, and snippets.

@beveradb
Created March 14, 2018 14:03
Show Gist options
  • Save beveradb/251b2637c92fcead3f7515e6a217bae2 to your computer and use it in GitHub Desktop.
Save beveradb/251b2637c92fcead3f7515e6a217bae2 to your computer and use it in GitHub Desktop.
PHP dump/log details of HTTP requests received
<?php
# Log string to file whilst also printing it to screen (stdout)
# Named tee to match the core unix command - https://en.wikipedia.org/wiki/Tee_(command),
# which in turn is named after the T-splitter used in plumbing.
function tee($message, $logFilepath)
{
file_put_contents($logFilepath, $message, FILE_APPEND);
echo $message;
}
$logFilepath = "/tmp/http-request-dump.log";
echo "<pre>";
tee("Processing Request: ".date("d/m/Y H:i:s"), $logFilepath);
tee("Headers: ".print_r(apache_request_headers(), true), $logFilepath);
$rawPOSTData = file_get_contents("php://input");
tee("\nRequest:\n".print_r($rawPOSTData, true), $logFilepath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment