I have created a PHP scipt to test some external system that is returning a JSON string. But there is HTML inside the JSON. I have tried setting a header but it ain't working.
Here is my code.
header("Content-type: application/json");
echo "{\"CarName\":\"Audi\",\"CarPrice\": \"100000USD\"}";
You can try and tell the browser to ignore the tracking injected code, but there's no guarantee your hosting isn't rewriting that header also, by manipulating Content-Length
:
$payload = json_encode( YOUR_ARRAY );
Header('Content-Type: application/json;charset=utf-8");
Header('Content-Length: ' . strlen($payload));
die($payload);
The solution, however, is either to get a different hosting or to contact them (there's all sorts of hosted frameworks that NEED proper JSON sent by PHP: is none of them working there? I find that difficult to believe) and ask how to not get injected trackers.