summaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2021-08-11 00:52:09 -0400
committerMalfurious <m@lfurio.us>2021-08-11 00:52:09 -0400
commit35eb45c4b6eebdf7ba907f412f55a3dff4c0d68d (patch)
treef472de9ed3f30fe58bdbbb35cbb4a8129d0d39fd /templates
parent58f7de7652190912ec741366f1ee1415dbb77c5c (diff)
downloadlib-des-gnux-35eb45c4b6eebdf7ba907f412f55a3dff4c0d68d.tar.gz
lib-des-gnux-35eb45c4b6eebdf7ba907f412f55a3dff4c0d68d.zip
Commit PHP request logging script
Taken from github, see comment in file. Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'templates')
-rw-r--r--templates/dumprequest.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/templates/dumprequest.php b/templates/dumprequest.php
new file mode 100644
index 0000000..8df493e
--- /dev/null
+++ b/templates/dumprequest.php
@@ -0,0 +1,49 @@
+<?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');