phphttphttp-headershttpresponse

How to get all the HTTP response headers of the current page in php


headers_list() and apache_reponse_headers() return a greatly reduced list of the actual response headers, even after headers_sent() and get_headers() would make another HTTP request.

So, how can you get the complete list of response headers that are to be sent with the current page, or are these additional response headers, as set by the server, only set long after PHP has finished?


Solution

  • headers_list() will only get you headers sent by PHP itself.

    However, the hosting webserver is free to add headers. For example, it may transparently compress php's output, set Strict-Transport-Security headers, and so on. In some setups (for example wikimedia's), the request is also proxied by another HTTP server on another machine to allow caching.

    Therefore, there is no way to get the complete list of sent HTTP headers other than to do a request to your own server and get headers for this request.