Sunny Khan Sunny Khan - 1 month ago 6
PHP Question

Why $http_response_header does not returns response header of the current page?

Under PHP VERSION 7.1.0

As i know that

$http_response_header
returns an associative array of response headers BUT when i simply put
$http_response_header
alone into my php file then it says
Notice: Undefined variable: http_response_header in C:\xampp\htdocs\myfiles\Research\index.php on line 2
instead of returning this error it should return the response headers of the current page that are receieved by the server localhost

But using it on
file_get_contents()
it works fine.

I am already at php.net on that issue, so please don't share the links to php.net in the answer.

Can anyone tell in easy words why is that happening ?

Answer Source

Even though you asked for not redirecting you back to php.net, I will still do that:

When using the HTTP wrapper, $http_response_header will be populated with the HTTP response headers.

This means, you have to use a Wrapper in your php script. Calling your document triggers a GET to your Apache but not a wrapper in your script.