Skip to content

Instantly share code, notes, and snippets.

@beppe9000
Forked from magnetikonline/dumprequest.php
Last active January 27, 2021 12:23
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 beppe9000/4bed78b426c64ccea4ece8ede9852218 to your computer and use it in GitHub Desktop.
Save beppe9000/4bed78b426c64ccea4ece8ede9852218 to your computer and use it in GitHub Desktop.
PHP script to dump full HTTP request to file (method, HTTP headers and body).
// usage: logRequest("/tmp/post-".time().".log");
function logRequest($targetFile){ $headerList = []; 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,' ','-'); $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"); }
GET /dumprequest.php HTTP/1.1
HTTP headers:
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Accept-Encoding: gzip, deflate, br
Referer: http://localhost/
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36
Upgrade-Insecure-Requests: 1
Connection: keep-alive
Host: localhost
Request body:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment