|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-12-30 13:04 UTC] laruence@php.net
[2015-12-30 13:04 UTC] laruence@php.net
-Status: Open
+Status: Closed
[2016-07-20 11:34 UTC] davey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
Description: ------------ file_get_contents() does not pass the headers in the stream context if it's given as a reference to an array, as exemplified below: $headers = ['Host: maisqi.com']; $httpContext = [ 'http' => [ 'header' => &$headers, ], ]; $uri = 'http://77.91.206.217/outros/bugs/php/_print_host_headers.php'; $content = file_get_contents($uri, false, stream_context_create($httpContext)); In PHP 5.6, this works flawlessly; on PHP7, the request is issued with no headers. If no reference is given ('header' => $headers), this works on both versions. Test script: --------------- $headers = ['Host: maisqi.com']; $httpContext = [ 'http' => [ 'protocol_version' => '1.1', 'method' => 'GET', 'header' => &$headers, 'follow_location' => 0, 'max_redirects' => 0, 'ignore_errors' => true, 'timeout' => 60, ], ]; $uri = 'http://77.91.206.217/outros/bugs/php/_print_host_headers.php'; $content = file_get_contents($uri, false, stream_context_create($httpContext)); echo "Content:\n"; if ($content === false) echo '-'; else if ($content === '') echo '(empty)'; else echo htmlspecialchars($content); echo "\n\n\$http_response_header:\n"; if (empty($http_response_header)) echo '-'; else print_r($http_response_header); Expected result: ---------------- It should print something like tbis: Content: HTTP_HOST: maisqi.com SERVER_NAME: maisqi.com $http_response_header: Array ( [0] => HTTP/1.1 200 OK [1] => Date: Wed, 30 Dec 2015 11:04:09 GMT [2] => Server: Apache [3] => Connection: close [4] => Content-Type: text/html; charset=utf-8 ) Actual result: -------------- It prints the HTML of a "Page Not Found" page, because no specific Host header is requested.