Frage

I'm writing a simple form to check if a .com domain is available. I'm evaluating 3 methods (@dns_get_record, gethostbyname() and checkdnsrr()) for a bunch of test domain names with the below code, but I am getting all not available entries for gethostbyname() and checkdnsrr(), which you can see @ http://suggestmyname.com/nonwp/arraypush.php if you refresh a few times. I don't get this issue when running on my local testing server, anyone know why the inconsistency? Also not all of the domains are being checked on my remote server, but are on my local testing server.

$sdomains = array();
array_push($sdomains, 'etc.com');

function domainAvailable1($domain){
$results = @dns_get_record($domain, DNS_ANY);
return empty($results);
}
function domainAvailable2($domain){
return gethostbyname($domain) == $domain;
}
function domainAvailable3($domain){
return !checkdnsrr($domain, 'ANY');
}

echo '<table><tr><td>@dns_get_record</td><td>gethostbyname</td><td>checkdnsrr</td></tr>';       

foreach($sdomains as $sdomain){
if (domainAvailable1($sdomain) == true){                    
            echo '<tr><td bgcolor=green>' . $sdomain . ' is available!</td>';
            } else {
            echo '<tr><td bgcolor=red>' . $sdomain . ' is NOT available.</td>';
            }
if (domainAvailable2($sdomain) == true){                    
            echo '<td bgcolor=green>' . $sdomain . ' is available!</td>';
            } else {
            echo '<td bgcolor=red>' . $sdomain . ' is NOT available.</td>';
            }
if (domainAvailable3($sdomain) == true){                    
            echo '<td bgcolor=green>' . $sdomain . ' is available!</td></tr>';
            } else {
            echo '<td bgcolor=red>' . $sdomain . ' is NOT available.</td></tr>';
            }
}
War es hilfreich?

Lösung

I'm not sure that using any of those functions (basically using DNS in general) is a reliable method to determine if a domain is available.

I have plenty of domains registered that have absolutely no DNS records so they can't be resolved by any means, but the domains are of course taken.

While most domains will have some DNS records, there will be cases where there aren't any. For example the domain mymoney.com in your script says it is available through all 3 checks, but the domain is registered.

Your best bet is to use WHOIS to query the appropriate registrar for a given TLD and use WHOIS to determine availability. I think if you try to use DNS, there will be false positives or other problems you will run into.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top