I have the following code that is supposed to output in the content-type: json.
public static function getTest()
{
header('Content-Type: application/json; charset=utf-8');
$result = ['foo' => 'bar'];
$json = json_encode($result);
echo $json;
}
On my production server (godaddy shared hosting - Apache 2.4.10 & PHP 5.4.31) the response type comes back: application/json. However on my local WAMP server (Apache 2.4.9 & PHP 5.5.12) the response type is 'text/html' (as seen in Firebug). This is causing me problems as I develop a series of API's that need to be json. My first guess was an apache mime type issue but that has not panned out for me.
Any ideas? I am sorry if this is perhaps more of a server config issue. But I am baffled and thought it possible that I missed something in my PHP.ini or even my code.
All help gratefully received. Thanks!
EDIT - I have fiddled with it a bit and learned something else. If I change the 'Content-type' to application/xml, my production server spits out the expected error reflecting the improperly formatted content for the xml standard. However, my local WAMP server still uses a response header with a content-type of text/html. Is there a setting to override header assignments in Apache or in PHP?