Beamtic's logo

Share via:

PHP: apache_response_headers

The apache_response_headers() function allows you to obtain some of the HTTP response headers that are sent by the Apache HTTP server; it does not return all the headers, so it might not do what you expect.


Edited: 2020-09-23 12:03

The apache_response_headers function is used to return certain HTTP response headers that are sent by the Apache web server, but it does not reveal all headers that are controlled by Apache, and therefor may not be very useful.

The function either returns an associative array on success or false on failure; the returned array contains key and value pairs for easy parsing.

Example use:

$apache_headers = apache_response_headers();


array(2) {
  string(6) "h2,h2c"
  string(7) "Upgrade"


  1. How to create a custom error handler for PHP that handles non-fetal errors.
  2. We can access other classes properties (variables) and methods (functions) by injecting the class object in the class that needs it.
  3. Setting custom HTTP Headers with cURL is useful when changing User Agent or Cookies. Headers can be changed two ways, both using the curl_setopt function.
  4. Should you use file_get_contnts or cURL when performing HTTP requests from PHP? It does not matter; but regardless of which you use, you should still handle errors properly!
  5. When using file_get_contents to perform HTTP requests, the server response headers is stored in a reserved variable after each successful request; we can iterate over this when we need to access individual response headers.

More in: PHP Tutorials