Why does php's file_get_contents incorrectly retrieve json files from xkcd?
- by hally
In writing a PHP script to download xkcd comics, i incurred errors when trying to get specific comics (as opposed to the latest one). Specifically, pointing file_get_contents at the following url:
xkcd.com/$COMIC_NUM/info.0.json
inexplicably retrieved the xhtml version of the comic's page on xkcd.com, and not a JSON file.
However, if i request the exact same url in my browser, the correct JSON file is downloaded.
I'm not sure why this is happening, but i suspect it has something to do with the request headers being sent.
Please help! :S