I am trying to set up a php script that returns some db entries to a json file. The script seems to be working when I read it from another website, however, when I try to read the output from the same folder (for testing purposes) it does not work. php code for generating the json:
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 01 Jan 1996 00:00:00 GMT');
header('Content-type: application/json');
//snipped sql magic
echo json_encode($rows);
When I visit the page on my site it will return what is expected:
[{"id":96,"name":"name1"},{"id":39,"name":"name2"}]
So far so good. However, when I try to read the output of this file in another php file in the same folder, like
$json = file_get_contents(urlencode('json.php')); //same result without the urlencode
echo var_dump($jsonData);
It will return the php code and not the content of the json file. I don't understand why this is. Any thoughts?