Hello guys, I have a small question about a domain availability function.. I'm inneed of an accurate function that returns a "1" if the checked domain is registered. At the moment im using this : function iswebexist($url) { $url = strtolower($url); $d = gethostbyname($url); if ($d!=$url) {return(1);} } ?> Code (markup): It works, but the problem is its only checking if the hostname is alive, not if its registered. Does anyone have ideas how to modify this function so that i can see results from domains that really are registered? Thanks in advance.
You need to use whois to see if a domain is registered. And you should cache the results because most (all?) whois servers rate-limit searches. Anyway, google for "php whois" and I'm sure you'll find lots of goodies.
If you have domain registrar account, check if your provider has API access (Enom does), then look for php class that implements this API. For example, this is how I use Enom API class available at phpclasses.org: require_once('class.EnomService.php'); $enom = new EnomService('username', '********', false, true); $result = $enom->checkDomain('domain_name', 'com'); PHP:
Thanks guys.. Im really not a programmer so i cant script this stuff on my own. So i need a little help I found this on some website: (http://www.bin-co.com/php/scripts/online/check_domain_availability/) function checkDomainAvailability($domain) { if(preg_match('/[;\&\|\>\<]/', $domain)) exit; //Could be a hack attempt exec("whois " . escapeshellarg($domain), $output); //:CAREFUL: $result = implode("\n", $output); return (strpos($result, 'No match for domain') !== false); } Code (markup): Can someone rewrite this function so it returns a "1" if a domain is registered? Thanks!
The returned results would have to be parsed and because of the varying nature of formats by different registrars this may be the "scenic route" to your solution. The API approaches mentioned above are more practical.
function checkDomainAvailability($domain) { if(preg_match('/[;\&\|\>\<]/', $domain)) exit; //Could be a hack attempt exec("whois " . escapeshellarg($domain), $output); //:CAREFUL: $result = implode("\n", $output); if (strpos($result, 'No match for domain') !== false){ return(1); } else { return(0); } } PHP: I didn't tested it, but it should work I hope this will help you.
the script works thanks for it, but this one gives very strange results hehe. So im going to try to learn more about the API solution. Its a better option i guess..
I found the solution i think $result = dns_get_record($url); if (!empty($result)) { return(1);} Code (markup): Easy and works better then my first attempt Thanks for your help guys!
It's kind of a 98% solution; domains that are registered but have no RRs are rare, but they do exist. To be completely accurate you need to use whois. But it may not be worth the trade-off, depends on your particular needs. Also your approach will fail to catch reserved and otherwise unavailable names. For example, there are no RRs for "r.com" but nevertheless is not open for registration. Whois would tell you this but DNS will not.
dns_get_record is what I recommend for quick domain check as well. I want to make a note however that in order to resolve a domain, it needs to have a nameserver record. So if you use DSN_NS as a second parameter it would be a lot quicker and efficient. (It is highly unlikely for registered domains to not have any name servers, but as someone pointed out they do exist). $result = dns_get_record($url, [B][COLOR="Blue"]DSN_NS[/COLOR][/B]); if (!empty($result)) { return(1);} Code (markup):