Beamtic's logo

HTTP Headers in PHP

  1. 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.
  2. Check if response headers has already been sent before attempting to send other headers.
  3. The PHP header function is used to send custom headers and response codes in response to HTTP requests.
  4. The headers_list() function will return a list of headers sent by PHP, or headers that are ready to be sent by PHP.
  5. 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.
  6. Article documenting the reasons to use Http_response_code instead of sending raw HTTP response codes in PHP.
  7. 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.