I'm implementing a REST service in PHP. This service should be able to support multiple input and output formats (JSON, XML). For that reason I want to check the request headers "Accept" and "Content-Type" for the type of content sent and requested by the client.
Accessing the "Accept" header is a simple as using $_SERVER['HTTP_ACCEPT']
. But accessing the "Content-Type" header seems to be a difficult task. I searched the PHP documentation and the web, but the only solution offered was the use of the PHP function apache_request_headers()
which is only supported when PHP is installed as an Apache module, which is not true in my case.
So my question now: How can I access the header "Content-Type" of a request?
$_SERVER["CONTENT_TYPE"]
is not always available. – user1898931 Dec 12 '12 at 19:42