-
-
Save jaywilliams/bee2512f0f12d6791315d6939119e135 to your computer and use it in GitHub Desktop.
PHP script to dump full HTTP request to file (method, HTTP headers and body).
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 | |
// https://gist.github.com/jaywilliams/bee2512f0f12d6791315d6939119e135 | |
// Forked: https://gist.github.com/magnetikonline/650e30e485c0f91f2f40 | |
// Usage: php -S localhost:8080 dumprequest.php | |
// Path to store all incoming requests | |
define('LOG_OUTPUT', __DIR__ . '/requests.log'); | |
$data = sprintf( | |
"[%s]\n%s %s %s\n\nHTTP HEADERS:\n", | |
date('c'), | |
$_SERVER['REQUEST_METHOD'], | |
$_SERVER['REQUEST_URI'], | |
$_SERVER['SERVER_PROTOCOL'] | |
); | |
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 | |
$data .= $name . ': ' . $value . "\n"; | |
} | |
} | |
$data .= "\nREQUEST BODY:\n" . file_get_contents('php://input') . "\n"; | |
file_put_contents(LOG_OUTPUT, $data, FILE_APPEND|LOCK_EX); | |
echo("OK!\n"); |
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
[2022-10-14T15:33:59+00:00] | |
GET /?test=hello HTTP/1.1 | |
HTTP HEADERS: | |
Host: localhost:8080 | |
User-Agent: Mozilla/5.0 (X11; OpenBSD amd64; rv:88.0) Gecko/20100101 Firefox/88.0 | |
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 | |
Accept-Language: en-US,en;q=0.5 | |
Accept-Encoding: gzip, deflate | |
Connection: keep-alive | |
Upgrade-Insecure-Requests: 1 | |
Cache-Control: max-age=0 | |
REQUEST BODY: | |
Thank you, this is more trivial than the original version
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, it just works :)