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?
PHP checkdnsrr() Function The checkdnsrr() function checks DNS records for type corresponding to host. We can use the checkdnsrr() function to check our DNS record to verify the existence of a domain name or not.
How to search for a domain. Navigate to https://domains.google.com/registrar. Enter your preferred domain name in the search box. Review the search results to determine if the domain is available.
The isSiteAvailible() function performs a cURL request with PHP and checks if the domain is available and online. Return TRUE if the specified website is available, otherwise, return FALSE if the website is offline. Uses: Call the isSiteAvailible() function and pass the website URL that you want to check.
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"; } ?>
It depends on what you mean by "available." If you mean available for registration, it is not possible to determine based on DNS information alone. The whois system must be used. An easy way to test is to take an unused domain name and set the nameservers to something invalid. DNS will not be available, but the domain is still unavailable for registration. I just tested the suggestions of checkdnsrr(), gethostbyname(), and dns_get_record(). All show that no DNS is returned for a domain that cannot be registered.
The following question offers some more details: Checking if a domain name is registered
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With