get_headers()
CURL で取得するのとは異なる結果を返す可能性があるのはどうしてですか? これが私のコードです:
header("Content-type: text/plain");
$url = 'http://www.foxbusiness.com/index.html';
echo "get_headers() headers:\n\n";
$headers = get_headers($url);
print_r($headers);
echo "\n\nCURL headers\n\n";
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url ) );
$headers = explode( "\n", curl_exec( $curl ) );
curl_close( $curl );
print_r($headers);
結果は次のとおりです。
get_headers() headers:
Array
(
[0] => HTTP/1.0 403 Forbidden
[1] => Server: AkamaiGHost
[2] => Mime-Version: 1.0
[3] => Content-Type: text/html
[4] => Content-Length: 283
[5] => Expires: Fri, 31 Aug 2012 07:29:14 GMT
[6] => Date: Fri, 31 Aug 2012 07:29:14 GMT
[7] => Connection: close
)
CURL headers
Array
(
[0] => HTTP/1.1 200 OK
[1] => Server: Apache
[2] => X-FoxNews-EdgeTTL: 2m
[3] => Content-Type: text/html;charset=UTF-8
[4] => Cache-Control: max-age=64
[5] => Date: Fri, 31 Aug 2012 07:29:14 GMT
[6] => Connection: keep-alive
[7] =>
[8] =>
)