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:
- User-Agent: Operating System, browser and its version number, â€¦
- Accept-Language: Requesting client language
- Accept-Charset: Character set of the client
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:126.96.36.199) 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.
1 thought on “Apache, PHP: Get Client Browser HTTP Request Headers Information”
Nice and simple function they have for this purpose. Thanks for the tip!
Comments are closed.