Skip to content

Instantly share code, notes, and snippets.

@andreaspollak
Forked from magnetikonline/dumprequest.php
Created September 3, 2020 20:41
Show Gist options
  • Select an option

  • Save andreaspollak/b4ecdb887a23c6adf48a73fb029ea767 to your computer and use it in GitHub Desktop.

Select an option

Save andreaspollak/b4ecdb887a23c6adf48a73fb029ea767 to your computer and use it in GitHub Desktop.

Revisions

  1. @magnetikonline magnetikonline revised this gist Oct 20, 2017. 2 changed files with 9 additions and 8 deletions.
    2 changes: 1 addition & 1 deletion dumprequest.php
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ public function execute($targetFile) {
    $data .= $name . ': ' . $value . "\n";
    }

    $data .= "\nResponse body:\n";
    $data .= "\nRequest body:\n";

    file_put_contents(
    $targetFile,
    15 changes: 8 additions & 7 deletions example.output.txt
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    GET /dumprequest.php HTTP/1.1

    HTTP headers:
    Host: localhost
    Connection: keep-alive
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36
    Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
    Accept-Encoding: gzip, deflate, br
    Referer: http://localhost/
    Accept-Encoding: gzip, deflate, sdch
    Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
    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

    Response body:
    Request body:
  2. @magnetikonline magnetikonline revised this gist Jun 6, 2015. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions example.output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    GET /dumprequest.php HTTP/1.1

    HTTP headers:
    Host: localhost
    Connection: keep-alive
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36
    Referer: http://localhost/
    Accept-Encoding: gzip, deflate, sdch
    Accept-Language: en-GB,en-US;q=0.8,en;q=0.6

    Response body:
  3. Peter Mescalchin created this gist Jun 22, 2014.
    49 changes: 49 additions & 0 deletions dumprequest.php
    Original file line number Diff line number Diff line change
    @@ -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 .= "\nResponse 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');