PHP Domain Availability Checking Script
READ ME!
This blog post is old now, the code has been refactored and now must be installed with composer, you can find the new package on packagist.
Skip To...
Introduction
First of all, This needs to be said, every script that I've seen out there that tries to check domain availability simply doesn't work, sucks or uses an unreliable method that is either too slow or just gives you errors, other than that there is the RoboWHOIS API, which is good for small projects, but it costs money and it's slow.
I created this script because I needed a quick, decently reliable and FREE way of checking if a domain is available (Not registered) for purchase, the application that I was building at the time that needed this functionality was my domain name generator site (No longer available).
Which randomly generates a string by combining various technology related words then checks to see if the generatedword.com(and various other TLD's) is available, it then links to various registrars(GoDaddy, NameCheap and NameSilo) where you get the option to register the domain name, I also added some affiliate links so that I could generate a few dollars if someone chooses to purchase the domain that my site generated for them.
At first I tried the HORRIBLE method of using GetHostByName, which pretty much just tried to get the IP address of the domain name.
The problem with this method is that, a Domain name can be registered and not assigned any IP address, nor point to any server at all.
So when that method seemed to fail very often, I googled around for an API that I could use, and found the RoboWHOIS API, without any other alternative, I purchased a few credits and started to implement this API.
It worked nicely and was reliable, the problem was speed, It was slow as shit when doing multiple requests in a semi-rapid succession(Like checking various TLD's at the same time), It also ate through credits like crazy, seeing as every user is going to consume one credit per TLD, per Refresh.
Queue the need for a dedicated script for the sole purpose of checking if a domain is avilable, If you're having the same problem I have, you can leave a thanks and a link to your project in the comments.
Enjoy!
Domain Availability Checking Script
=> Code has been moved to GitHub <=
How to use:
Include the file containing the script
include('DomainAPI.php');
$Domain = new DomainAvailability();
$available = $Domain->is_available("helgesverre.com");
$available
will now be either TRUE(if the domain is available) or FALSE(if it is not available).
So now you could use this in a project like this (Replace helgesverre.com with whatever domain you want to check).
include('DomainAvailability.php');
$Domain = new DomainAvailability();
$available = $Domain->is_available("helgesverre.com");
if ($available) {
echo "The domain is not registered";
} else {
echo "The domain is registered";
}
Have you found a creative way to use this script? Tell us in the comments! :D
Bugs and TODOs:
- If the WHOIS has some sort of request limiting then my script will always return FALSE.
- This can be fixed by either implementing some sort of proxy rotation system into the code.
- Or by handling this event by adding another field in the
$whois_arr
to look for request limiting messages like: "Your requests are too fast, please slow down". - The way the script receives data from the WHOIS server could probably be simplified or improved.
- The
$whois_arr
contains every known TLD, although some of them are missing the WHOIS server and its "Not Found" string. - I manually checked the replies from every single WHOISserver that I've filled out in the list and copy pasted the "not found" string into the script manually.
- Some of the TLD's that was listed in the IANA Database did not have a WHOIS server listed, you might have to do some digging to find those manually.
Credits and License
Script written and created by Helge Sverre.
This work is
licensed under a
Creative Commons Attribution-ShareAlike 4.0 International License.
If you use this script anywhere or modify it, please link back to my website and send me an email with your work :D