(PHP) Adventures in Getting an External File
I'm starting to get into PHP since my new job uses Expression Engine running on PHP. Yesterday one of the devs ran into something very interesting; file_get_contents was not returning anything when we pointed at our own site, but pointing at some other public site (google.com in our test case) worked fine.
Playing around and looking for other approaches I also tried to open using the file function:
No dice. Using some error trapping and Fiddler, it appeared that we weren't even getting any type of response (not even a 403 or 500). Turns out that we needed to use our internal IP address; once we did that it worked, both methods. I have to admit I'm still unsure as to why, and want to dig into this some more to find out. My current guess is that there's some type of configuration setting on our servers that was actively preventing the DNS look-up. But that's just a guess.
Oh, and the other bit I learned was that to suppress error messages in PHP you put the @ symbol in front of the function; then you can control the error trapping.
@file_get_contents($url);
if (strpos($http_response_header[0], "200")) {
echo "SUCCESS";
} else if (strpos($http_response_header[0], "400")) {
echo "400";
} else {
echo "FAILED";
}
If anyone can point me at the specific reasons for why domain lookup would be disabled, I'd love to learn about it.
Anyways, today I'm back to what I know - HTML5 CORS.