48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
class DumpHTTPRequestToFile {
|
|
private static 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;
|
|
|
|
return [];
|
|
}
|
|
|
|
public static function execute($targetFile) {
|
|
$data = sprintf(
|
|
"%s %s %s\n\nHTTP headers:\n",
|
|
$_SERVER['REQUEST_METHOD'],
|
|
$_SERVER['REQUEST_URI'],
|
|
$_SERVER['SERVER_PROTOCOL']
|
|
);
|
|
foreach (self::getHeaderList() as $name => $value) {
|
|
$data .= $name . ': ' . $value . "\n";
|
|
}
|
|
|
|
$data .= "\nRequest body:\n";
|
|
|
|
file_put_contents(
|
|
$targetFile,
|
|
$data . file_get_contents('php://input') . "\n",
|
|
FILE_APPEND | LOCK_EX
|
|
);
|
|
|
|
//echo("Done!\n\n");
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|