SHARE
TWEET

test.php

a guest May 19th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
  3. class DumpHTTPRequestToFile {
  4.  public function execute($targetFile) {
  5.   $data = sprintf(
  6.    "%s %s %s\n\nHTTP headers:\n",
  7.    $_SERVER['REQUEST_METHOD'],
  8.    $_SERVER['REQUEST_URI'],
  9.    $_SERVER['SERVER_PROTOCOL']
  10.   );
  11.   foreach ($this->getHeaderList() as $name => $value) {
  12.    $data .= $name . ': ' . $value . "\n";
  13.   }
  14.   $data .= "\nRequest body:\n";
  15.   file_put_contents(
  16.    $targetFile,
  17.    $data . file_get_contents('php://input') . "\n"
  18.   );
  19.   echo("Done!\n\n");
  20.  }
  21.  private function getHeaderList() {
  22.   $headerList = [];
  23.   foreach ($_SERVER as $name => $value) {
  24.    if (preg_match('/^HTTP_/',$name)) {
  25.     // convert HTTP_HEADER_NAME to Header-Name
  26.     $name = strtr(substr($name,5),'_',' ');
  27.     $name = ucwords(strtolower($name));
  28.     $name = strtr($name,' ','-');
  29.     // add to list
  30.     $headerList[$name] = $value;
  31.    }
  32.   }
  33.   return $headerList;
  34.  }
  35. }
  36. (new DumpHTTPRequestToFile)->execute('bc.txt');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top