如何使用PHP / apache访问原始HTTP请求数据?

时间:2023-01-09 20:16:30

I was wondering if there was a way to get at the raw HTTP request data in PHP running on apache that doesn't involve using any additional extensions. I've seen the HTTP functions in the manual, but I don't have the option of installing an extension in my environment.

我想知道是否有办法获得在apache上运行的PHP中的原始HTTP请求数据,该数据不涉及使用任何其他扩展。我已经在手册中看到过HTTP功能,但是我没有在我的环境中安装扩展的选项。

While I can access the information from $_SERVER, I would like to see the raw request exactly as it was sent to the server. PHP munges the header names to suit its own array key style, for eg. Some-Test-Header becomes HTTP_X_SOME_TEST_HEADER. This is not what I need.

虽然我可以从$ _SERVER访问信息,但我希望看到原始请求与发送到服务器完全一样。 PHP会根据自己的数组键样式来管理标题名称,例如。 Some-Test-Header变为HTTP_X_SOME_TEST_HEADER。这不是我需要的。

3 个解决方案

#1


10  

Do you mean the information contained in $_SERVER?

你的意思是$ _SERVER中包含的信息?

print_r($_SERVER);

Edit:

Would this do then?

那会这样吗?

foreach(getallheaders() as $key=>$value)  {
    print $key.': '.$value."<br />";
}

#2


12  

Use the following php wrapper:

使用以下php包装器:

$raw_post = file_get_contents("php://input"); 

#3


2  

Try this:

  $request = $_SERVER['SERVER_PROTOCOL'] .' '. $_SERVER['REQUEST_METHOD'] .' '. $_SERVER['REQUEST_URI'] . PHP_EOL;

  foreach (getallheaders() as $key => $value) {
    $request .= trim($key) .': '. trim($value) . PHP_EOL;
  }

  $request .= PHP_EOL . file_get_contents('php://input');

  echo $request;

#1


10  

Do you mean the information contained in $_SERVER?

你的意思是$ _SERVER中包含的信息?

print_r($_SERVER);

Edit:

Would this do then?

那会这样吗?

foreach(getallheaders() as $key=>$value)  {
    print $key.': '.$value."<br />";
}

#2


12  

Use the following php wrapper:

使用以下php包装器:

$raw_post = file_get_contents("php://input"); 

#3


2  

Try this:

  $request = $_SERVER['SERVER_PROTOCOL'] .' '. $_SERVER['REQUEST_METHOD'] .' '. $_SERVER['REQUEST_URI'] . PHP_EOL;

  foreach (getallheaders() as $key => $value) {
    $request .= trim($key) .': '. trim($value) . PHP_EOL;
  }

  $request .= PHP_EOL . file_get_contents('php://input');

  echo $request;