Created
March 14, 2018 14:03
-
-
Save beveradb/251b2637c92fcead3f7515e6a217bae2 to your computer and use it in GitHub Desktop.
PHP dump/log details of HTTP requests received
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 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