views:

194

answers:

1

When I call the following:

file_get_contents('http://whgfdw.ca');

or

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://whgfdw.ca');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);

The return value is the HTML of the homepage of the main site located on the local (dedicated) webserver. I would be grateful if anyone could help me understand this? Perhaps there is something I'm overlooking.

I can't use simple URL validation because http://whgfdw.ca is a perfectly fine URL; it just doesn't have a DNS entry.

My ideal functionality is to be able to catch a DNS lookup failure or a 404 or a case of no content and then act on it. Thanks!

+1  A: 

If you got a valid response then that DNS entry exists somewhere. It may be on an internal DNS server, in the /etc/hosts file of the local server or somewhere else in the stack but the bottom line is its being resolved in some way. So the question becomes wheres the entry its resolving to entered. Its possible that there is an application that is set to resolve all lookups to the local server (similar to how openDNS and many ISP's will resolve an un-resolved DNS name to their search page).

Given that its somehow being resolved there really isnt a way to validate it unless you compare the content of the response to some content you expect. Catching a 404 is pretty easy, you can also set up reverse lookup in php to catch unresolved names i believe. But you need to tackle that resolution first i should think.

prodigitalson