How do I write raw HTTP headers using a PHP script?

I am using a cURL script to send POST data through a proxy to a script, and I want to see which HTTP headers the cURL script sends. List of things I tried:

  • echo curl_getinfo($ch, CURLINFO_HEADER_OUT) does not display the result.
  • file_get_contents('php://input') gets some HTTP headers, but not all.
  • print_r($_SERVER) also receives some HTTP headers, but not all (I know this because there should be an X-Forwarded-For header, but it doesn't)
  • Printing all super valves ($ _POST, $ _GET, $ _REQUEST, $ _FILES, etc.) still doesn’t show raw HTTP headers.
  • http_get_request_headers(), apache_request_headers(), $http_response_header, $HTTP_RAW_POST_DATADo not take everything.

reference

+5
source share
3 answers

CURLOPT_HEADER, CURLINFO_HEADER_OUT, \r\n\r\n ( ) 2:

<?php
$ch = curl_init('http://www.yahoo.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$result = curl_exec($ch);
if ($result !== false) {
    $split_result = split("\r\n\r\n", $result, 2);
    $header = $split_result[0];
    $body = $split_result[1];
    /** Process here **/
} else {
   /** Error handling here **/
}
+3

CURLINFO_HEADER_OUT:

CURLINFO_HEADER_OUT
TRUE .
PHP 5.1.3. CURLINFO_ .

http://www.php.net/manual/en/function.curl-setopt.php

:

<?php

$ch = curl_init('http://www.google.com');
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

echo curl_getinfo($ch, CURLINFO_HEADER_OUT);
+1

Apache, apache_request_headers() , .

, $_SERVER, -.

0

All Articles