How do you check if a domain name exists?

19,947

Solution 1

http://php.net/manual/en/function.checkdnsrr.php

if (checkdnsrr('test.nl', 'A')) // or use ANY or for other see above link
{
    echo 'Domain exists';
}
else
{
    echo 'Domain does not exist';
}

Solution 2

http://whois.net/ any good?

Solution 3

PHP:

$URL = "http://www.dotnetindex.com/articles/5261-Article--AJAX-Tips-and-Tricks.asp";
$PARSED_URL = parse_url($URL);
$DOMAIN = $PARSED_URL['host'];
$ip = gethostbyname($DOMAIN);

if($ip===$DOMAIN)
{
    echo "Url does not exist";
}
else
{
    echo "Url exists";
}

Solution 4

Do you want to know if the domain is registered, or if it's actually present in the DNS ?

If the former, then whois based approaches are the only viable way, and even then you'll run into massive issues parsing the highly varied output from the various TLDs whois servers.

If the latter, a simple DNS lookup will suffice.

Share:
19,947
David
Author by

David

Member of the knight who say "NIH".

Updated on June 14, 2022

Comments

  • David
    David almost 2 years

    Not only easy ones like .com or .net, but also, .co.uk, .fr, .gov.rw ... ?

    Should I really make a huge mapping "tld to relevant whois server", or is there an easier way ?

  • Kurt
    Kurt over 15 years
    Not a good check, for example example.org may not point to an IP but www.example.org may point to a valid IP (example.org may only have NS and MX records).
  • user2477139
    user2477139 over 8 years
    Hello mike when i add wrong url in this it even says domain exisit for example adfsfsdf.com it says domain exists.i tried many other php function but all having same problem
  • Bikash Ranjan
    Bikash Ranjan over 8 years
    I guess "." is missing after domain name like test.com. if (checkdnsrr('test.nl.', 'ANY')) // or use ANY or for other see above link { echo 'Domain exists'; } else { echo 'Domain does not exist'; }
  • Patrick Mevzek
    Patrick Mevzek over 6 years
    Two wrong advises: do not use the DNS to check if a domain name exists (because a domain name can be registered but not delegated) and do not use the ANY resource type as it does not do what you think it does (and if you were at the stage of using the DNS you should query the authoritative nameservers, not recursive ones, where ANY is used)