Last updated on December 2, 2022
Today I would like to share a PHP code snippet that lets you know if a given specific domain is registered or available for purchase or not.
To check if a domain is registered or not we will use the PHP’s built-in function called checkdnsrr()
This function searches for the DNS records of the given domain and if they are not available that means the domain is not registered and it is available.
Here is a simple script that you can use:
function is_domain_available($domain) {
return checkdnsrr($domain, 'ANY') ? $domain . ' is already registered' : $domain . ' is available';
}
How to use
you need to pass the domain name to the function.
$domain = 'arjunphp.com';
echo is_domain_available($domain);
// output:arjunphp.com is already registered.