开发者

PHP curl and file_get_contents returns the main website located on the server when I enter a valid URL without DNS resolution

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 开发者_JS百科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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜