Reputation: 397
I am using the following code to check to see if the dns entry exists for a domain (basically to validate the domain is real)...
$sdip = gethostbyname("www.nonexistancedomainsdlkmsaldsa.com.");
$sddomain = gethostbyaddr($sdip);
print "IP: $sdip\n";
print "Domain: $sddomain\n";
It is returning....IP: 67.215.65.132 Domain: hit-nxdomain.opendns.com
So I am assuming that it is in fact searching for www.nonexistancedomainsdlkmsaldsa.com.myhostname.com (not exactly sure on this).
I read the article on php.net about adding a .
following the domain, so I tried this and it didn't change anything. Anyone understand why I'm getting this? Basically, here is what I am trying to do...
User enters domain name (no http/https)....it checks to see if domain exists, if it does, it continues my script, if it does not exist, it fails with an error message.
I want them to be able to enter ANY valid domain name and it check it. So any other solutions would be helpful if there is anything better. Basically I am using this as a validation to see if domain name exists.
I would also (if at all possible), like to find out how to check regexp for sub.subdomain.domain.tld where sub and subdomain are not required (basically to see if format is a valid format). I have searched stackoverflow, but they don't get into the detail I need to allow sub.subdomain but not require them.
article on php.net:
If you do a gethostbyname() and there is no trailing dot after a domainname that does not resolve, this domainname will ultimately be appended to the server-FQDN by nslookup.
So if you do a lookup for nonexistentdomainname.be your server may return the ip for nonexistentdomainname.be.yourhostname.com, which is the server-ip.
To avoid this behaviour, just add a trailing dot to the domainname; i.e. gethostbyname('nonexistentdomainname.be.')
it isn't in fact returning my server IP (i overlooked that). So I don't know if that article is relevant to this problem or not. I will leave it just in case it is.
Upvotes: 0
Views: 299
Reputation: 522510
It sounds like you're using OpenDNS as your DNS server. When you query OpenDNS for a non-existent domain, they will redirect you to one of their own "search result" pages/servers. This is specifically for OpenDNS, other DNS servers should not behave this way and correctly return no result.
Upvotes: 2