Categories
Apache Web Server Tutorials & Tips HTTP Tips & Tutorials PHP Tips & Tutorials

Apache, PHP: Get Client Browser HTTP Request Headers Information

Every HTTP requests made by any client web browsers to an Apache should conform to the HTTP specification and provide certain set of headers information for the server to parse and understand. Useful headers information that can be retrieved in PHP by function apache_request_headers() includes:

  1. User-Agent: Operating System, browser and its version number, …
  2. Accept-Language: Requesting client language
  3. Accept-Charset: Character set of the client
  4. …

To get an array of the above client request headers information, just use apache_request_headers() function:

$headers = apache_request_headers();

And you’ll get:

Array
(
    [Host] => localhost
    [User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 GTB5
    [Accept] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [Accept-Language] => en-us,en;q=0.5
    [Accept-Encoding] => gzip,deflate
    [Accept-Charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
    [Keep-Alive] => 300
    [Connection] => keep-alive
    [Cache-Control] => max-age=0
)

Similarly, you can use apache_response_headers() to get the HTTP response headers information sent from your server to the client.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

One reply on “Apache, PHP: Get Client Browser HTTP Request Headers Information”

Comments are closed.