Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 457
MrWhite Avatar asked Oct 28 '25 20:10

MrWhite


1 Answers

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.

like image 135
phihag Avatar answered Oct 30 '25 12:10

phihag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!