Skip to content

Instantly share code, notes, and snippets.

Forked from magnetikonline/dumprequest.php
Last active November 8, 2023 12:28
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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).
// Forked:
// 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",
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);
GET /?test=hello HTTP/1.1
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
Copy link

dkeza commented Mar 6, 2023

Thank you, it just works :)

Copy link

skylert7 commented Sep 4, 2023

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