<?php | |
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40 | |
class DumpHTTPRequestToFile { | |
public function execute($targetFile) { | |
$data = sprintf( | |
"%s %s %s\n\nHTTP headers:\n", | |
$_SERVER['REQUEST_METHOD'], | |
$_SERVER['REQUEST_URI'], | |
$_SERVER['SERVER_PROTOCOL'] | |
); | |
foreach ($this->getHeaderList() as $name => $value) { | |
$data .= $name . ': ' . $value . "\n"; | |
} | |
$data .= "\nRequest body:\n"; | |
file_put_contents( | |
$targetFile, | |
$data . file_get_contents('php://input') . "\n" | |
); | |
echo("Done!\n\n"); | |
} | |
private function getHeaderList() { | |
$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,' ','-'); | |
// add to list | |
$headerList[$name] = $value; | |
} | |
} | |
return $headerList; | |
} | |
} | |
(new DumpHTTPRequestToFile)->execute('./dumprequest.txt'); |
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: |
This comment has been minimized.
This comment has been minimized.
@beebopfr |
This comment has been minimized.
This comment has been minimized.
Hello, It's a very useful script would be useful if it can dump |
This comment has been minimized.
This comment has been minimized.
Nice script, thank you! |
This comment has been minimized.
This comment has been minimized.
hi , thanks in advance |
This comment has been minimized.
This comment has been minimized.
To add every new register instead of replacing the previous one, you must use FILE_APPEND with file_get_content. |
This comment has been minimized.
This comment has been minimized.
Use this line to get GET/POST data $data . print_r($_REQUEST,true) . "\n*************************************************************\n", FILE_APPEND |
This comment has been minimized.
This comment has been minimized.
add this line at the end to create a file for each request with timestamp $date = new DateTime(); |
This comment has been minimized.
This comment has been minimized.
This doesn't need to be a class, could be a easy to use library function. |
This comment has been minimized.
This comment has been minimized.
Hey! thanks for this script. I'm a complete newbie and maybe I can not even explain myself. However what I need is to save data coming from an http request to my server on a file. Thus it seems that the above script is perfect for my needs. thanks in advance |
This comment has been minimized.
This comment has been minimized.
For the next time I come across this- Single function version.
|
This comment has been minimized.
This comment has been minimized.
@jotham thanks for summarizing it |
This comment has been minimized.
This comment has been minimized.
Simple, but useful snippet. :) |
This comment has been minimized.
Hey ! Thanks for this helpfull script !
My suggestions :