David19801 David19801 - 6 months ago 16
PHP Question

check to see if a domain is available or not using PHP?

If I have a domain like

www.example.com
and I want to check if it is available using DNS records (not whois)...

Is it possible to do this using PHP?

Answer

You can use checkdnsrr or gethostbyname:

Documentation:

http://www.php.net/checkdnsrr

http://www.php.net/gethostbyname

Example checkdnsrr:

<?php
 if ( checkdnsrr('example.com.', 'ANY') ) {
  echo "DNS Record found";
 }
 else {
  echo "NO DNS Record found";
 }
?>

Example gethostbyname:

<?php
 $domain = 'example.com';
 if ( gethostbyname($domain) != $domain ) {
  echo "DNS Record found";
 }
 else {
  echo "NO DNS Record found";
 }
?>
Comments