How to print all information from an HTTP request to the screen, in PHP

后端 未结 9 1929
温柔的废话
温柔的废话 2020-12-08 01:55

I need some PHP code that does a dump of all the information in an HTTP request, including headers and the contents of any information included in a POST request. Basically,

9条回答
  •  不知归路
    2020-12-08 02:15

    Putting together answers from Peter Bailey and Cmyker you get something like:

     $value) {
        if (strpos($key, 'HTTP_') === 0) {
            $chunks = explode('_', $key);
            $header = '';
            for ($i = 1; $y = sizeof($chunks) - 1, $i < $y; $i++) {
                $header .= ucfirst(strtolower($chunks[$i])).'-';
            }
            $header .= ucfirst(strtolower($chunks[$i])).': '.$value;
            echo $header."\n";
        }
    }
    $body = file_get_contents('php://input');
    if ($body != '') {
      print("\n$body\n\n");
    }
    ?>
    

    which works with the php -S built-in webserver, which is quite a handy feature of PHP.

提交回复
热议问题