Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 593
David19801 Avatar asked Jan 01 '12 14:01

David19801


People also ask

How can I check if a domain is available in 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 do I check if a domain is available?

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.

How do you check website is up or down in PHP?

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.


2 Answers

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";  } ?> 
like image 99
favo Avatar answered Sep 19 '22 22:09

favo


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

like image 31
Matthew Kolb Avatar answered Sep 23 '22 22:09

Matthew Kolb