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.
Domain Availability Checking Script
=> Code has been moved to GitHub <=
How to use:
Include the file containing the script
1 2 3 4 5 |
include ('DomainAPI.php'); $Domain = new DomainAvailability; $available = $Domai->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).
1 2 3 4 5 6 7 8 9 10 11 |
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 WHOIS server 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
when i run this script all i get is a black page. noting at tall
What do you mean by “run the script”, are you using it in an application or did you just copy paste everything into a .php file and thought it would work like that?
Let me see your code and ill try to help you out.
Thanx for the script ..
could you please help me with a problem i am encountering a problem:
” Fatal error: Can’t use function return value in write context in D:\xampp\htdocs\domiancheck\DomainAvailability.php on line 591″
public function get_tld ($domain) {
// this checks the domain string to see if it has “www.” included at the end
/*line591*/ if ( !substr($domain, strpos($domain, “www.”)) || empty(substr($domain, strpos($domain, “www.”))) ) {
// If “www.” is not found in the domain string then set the offset to 0
$domain_offset = 0;
} else {
// If “www.” is found in the domain string then set the offset to 4
$domain_offset = 4;
}
so what i did to make it work was omit the above code and set $domain_offset = 4;
is_available($domain) . $domain values i tested for ” “, example , example.com, http://www.example.com
hmm…
You might have downloaded an old version, Try to use the latest version from the GitHub repo:
https://github.com/HelgeSverre/Domain-Availability
I agree with @LAL
I have the same issue
could you put the code that you are using up on github/gist) or on pastebin?
same issue here
latest version / no code changes:
example.php:
Fatal error: Can’t use function return value in write context in DomainAvailability.php on line 586
Which domain did you test with and which PHP version are you using?
I just updated the code today, Maybe try the latest version.
Hi Helge,
On the current code on Github (8/11/2014, latest commit c7e6164c9a) , there are some small issues with parenthesis:
On line 589: if ( !$hasWWW) || empty($hasWWW)) ) {
should be: if ( !$hasWWW || empty($hasWWW)) {
(one right parenthesis to much…)
On line 586: $hasWWW = substr($domain, strpos($domain, “www.”);
Should be: $hasWWW = substr($domain, strpos($domain, “www.”) );
(one missing right parenthesis…)
Sure, on the whole the number of right parenthesis is correct, but that doesn’t do the job!
After these modifications, the code works perfectly, it’s great.
I am using it for some testing now.
However, I have one question (the 1 million dollar one): how to deal with the whois requests limit ?
Tom
Arghhhhh, damn, Note to self: always test before committing.
Fixed the error, tested and committed, thanks a lot :)
Well I have implemented an “unreliable” check that will run first before querying the whois servers, it uses the gethostbyname() function that will return the same string passed to it if the hostname passed to it does not have an IP( 80% ~of domains will be assigned an IP, … kind of), if
the function fails, it will fall back to querying the WHOIS server directly, this is to reduce the requests that is sent to the whois server.
If that is not enough, I would include some sort of proxy rotation scheme:
1. Scrape a bunch of proxies
2. Put them in a file (you could create a python script for this)
3. Create a function in the DomainAvailability class to import the proxies (into an array?)
4. Rotate them on each query to the whois server.
If anyone has a better solution I’d love to hear it.
Hello Helge,
I am testing this script in my wamp server.
When i use this script for 3 to 4 domains inside a for loop it will take around 30 Seconds to give the results.
but in your http://helgesdomaingenerator.com/ site it only takes a second load results for 9 domains.
Please give solution so that i can improve the speed like your demo site.
Thanks.
The speed issue might have to do with the fact that you are developing locally, Sometimes even if you’ve got an awesome connection it might be slower than a web host that is located in a Data center and practically has a connection straight into the backbone of the internet, which means that it can send the requests and receive the response a lot faster.
That is the only thing I can think of to be honest, I didn’t make any other changes to the code on Helgesdomaingenerator.com other than put the function in a loop.
thanks sir.
You’re welcome :)
Thanks, this is a great script. I was able to successfully implement it with Laravel as a model. Quite powerful. Really appreciate it.
One question though, how do I find out what .com.bd or .org.bd or .in or .pw etc WHOIS servers are? because the common TLDs are not always the case.
Thanks.
Thank you :)
.in and .pw are already implemented and their whois servers are:
.in – whois.inregistry.net
.pw – whois.nic.pw
For the com.bg domains those are just “glorified subdomains” of the .bd, What I’d do for those kind of special TLD’s is to add them to the list regardless of it being a regular.bd tld then try to find the whois server that controls the root .db tld, Which I’ve tried to find for awhile not but I can’t seem to get working, but it seems like it’s “official” whois server was dns.bd
So to make them work you would have to add these lines to the whois server array:
".bd" => array("dns.bd","MATCH"),
".com.bd" => array("dns.bd","MATCH"),
".org.bd" => array("dns.bd","MATCH"),
".net.bd" => array("dns.bd","MATCH")
Thanks. I looked around the web and I don’t think the .bd tld whois server is dns.bd. This is very confusing. Thanks for this awesome script. Works like a charm. I had tried many other things.
@yosuf kamal bhai,
help me bro.i can’t still figure it out!!! .bd tld server may be wrong…its not working for me..please paste the right configure!!
Hi, I’m very sorry to inform you that BTCL has yet to develop and open API through which you can check availability of *.bd domains. No wonder. So this is not going to happen anytime soon. You cant even check the availability in their website, you can only find the information about the sites that already exist. stupid, no?
That’s stupid :c
Hey sir
How to do this in laravel 5? Now I want to develop this domain concept in one we
Hi Mr. Helge;
I have to say thank you for this cool programm.
I want to check .ir domain but all kind of .ir domains get the same result and that’s FALSE…
This is my code…
Would you help me?
CODE:
include (“domain_availability/DomainAvailability.php”);
$domain = trim( $_POST[‘domain_name’] );
$Domain_init = new DomainAvailability(true);
$available = $Domain_init->is_available($domain);
if ( $av… ) {}
else {}
Thanks, the error you are getting is due to me not having checked the response the WHOIS server sends back when it finds an invalid domain, I will test and updated the code later today to support .ir domains
Thanks alot for your support…
Be good…
You’re welcome :)
I’m still waiting for your support…
Thank you again…
What do you need?
May be it’s because of my English comprehension, but I thought you said “…You’ll be update the code for support .ir domains…”
Actually I checked the whois servers in your code and every thing seems to be right there.
There is a whois server for .ir domains in this line:
“.ir” => array(“whois.nic.ir”,”MATCH”),
but still I can’t check ir domain.
It’s very kind of you if you help me out…
Take care…
Oh shit, I totally forgot about that, I will do that right now.
EDIT: Here, added support for .ir domains:
https://github.com/HelgeSverre/Domain-Availability/blob/master/DomainAvailability.php
You’re the best… ;-)
Thanks :)
:)
Thanks alot… I checked a few scripts for check domain availability on the NET, but your script is madly fast…
and .ir issue is fixed…
I’m a composer and this is one of my songs:
accept it for my special thanks…
https://soundcloud.com/kiyarash3tar/in-love
Thank you :)
Beautiful song.
Hi Sir!
Great Work i love this. really appriciating.
please add .pk , .com.pk , .org.pk,.net.pk and edu.pk.
thanks :)
ill work on it! :)
Heys realy nice code. thank you :)
always give the result FALSE.
What tld are you checking?
Hows this working nowadays? Can it check availability for all international tld? What if you check 300k in 1 day, will the whois end up limiting you, that would be a big problem.
The script needs to be rewritten, as for checking 300k in 1 day, nope, that will get you rate limited or blocked from the whois server, you could use a proxy, but I will have to rewrite the entire thing to support that.
aw ok, gotcha, ya Im actually looking for a solid script or bot to check internation tld availabilities. Im so sick of these programs that are either slow, limit, freeze, etc. Since Im on a large scale I also need consistency, efficiency. Sooo, Im still on the hunt. Thanks for your reply tho
Well if you are checking on a large scale you will need proxies as most whois servers rate-limit individual IP addresses to x requests / second, by using proxies you can just switch to another IP when you’ve hit your limit, I am planning to write a program or class that supports that kind of large scale checking, but we’ll see.
Hi Helge,
i’m appreciate your php files, can you please make include files,e.g domain.txt instead of write domains on example.php.
Thanks for your help
You could enter the domains you want to check for then loop through them in PHP, bear in mind that if you make a lot of concurrent requests, the WHOIS server’s might temporary blacklist your IP.
Nice Script. I want to use it.
You are free to use it if you want :)
Good one!
Thanks :)
Not working at all!
Fatal error: Uncaught exception ‘Exception’ with message ‘Invalid domain extension’ in /public_html/AvailabilityService.php:471
Let me see the code that you used?
get error while running example.php file
Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\kanu\demo\Domain-Availability-master\example.php on line 2
Fatal error: require(): Failed opening required ‘vendor/autoload.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\kanu\demo\Domain-Availability-master\example.php on line 2
Did you run composer?
Hello,
How can I check a .ke domain for Kenya?
The script aint working
What error are you getting, copy paste your code into gist.github.com and link it here.
I think I’m doig something wron as I am only getting a blank page when I try to run the script using the example page.
Here is the code I’m using
require (‘src/AvailabilityService.php’);
$Domain = new DomainAvailability;
$available = $Domain->is_available(“helgesverre.com”);
if ($available) {
echo “The domain is not registered”;
} else {
echo “The domain is registered”;
}
I think you forgot to use the namespace, try this:
thanks, though I think the problem was that I was trying to run it as a script instead of using composer.json
I dont have shell access to the account, is there any way of using this as a script?
Go to the github page and download the AvailabilityService.php file and include it, then it should work.
Hello Helge. Would you please help me with integrating your script with a WordPress site?… Thank You.
I can certainly help you integrate my script, but I will apply my standard rate of $80 USD / Hour.
If that is not a problem, you can send me a message on my contact form and we can get started. :)
I am running script on a localhost at the moment and trying to get this script to work (I am fairly new to php).
I keep getting this error:
Fatal error: Class ‘HelgeSverre\DomainAvailability’ not found in C:\wamp\www\transit\products – Copy.php on line 53
this is the code i am using:
is_available(‘helgesverre.com’);
if ($available) {
echo ‘The domain is not registered’;
} else {
echo ‘The domain is registered’;
}
?>
Any help would be appreciated, thanks :)
sorry, code:
require (‘src/AvailabilityService.php’);
$Domain = new HelgeSverre\DomainAvailability();
$available = $Domain->is_available(‘helgesverre.com’);
if ($available) {
echo ‘The domain is not registered’;
} else {
echo ‘The domain is registered’;
}
are you sure that the file is being included properly?
Try double checking the path to the AvailabilityService.php file.
Hello
Helge Sverre Hessevik Liseth. I have one problem. When i check domain name on localhost like use xampp then i works fine, but when i upload it on server then its not works. But why?
Which PHP Version is running on your web host?
Do you get any error messages?
Try turning on error reporting and see what the error messages say.
Hi, Thanks for code.
It was working till 2 days ago although with few wrong answers. but now I get false all the time. (isAvailable function)
Any help will be appreciated
Have to say but now again I get the correct answer!! Is there anything to do to handle this condition? Also furthermore I’m in Iran, is it possible it happens do to boycott?? :| :((
Depending on how much you are using the script, you might have become temporary blacklisted by the WHOIS servers, each WHOIS server has their own “acceptable use”-limit.
But I believe that’s not the issue. because I face it even at the beginning of testing after a day
Which TLD’s were you testing?
com, co, ir and so on
Nice API, but i wonder..
What is the difference between this API/whois servers, and others pay per use?
And between this and a registrar api, like GoDaddy?
What is the difference in term of fresh data retrieved between these methods for .com?
Hello, Helge. I just downloaded the Zip file from github.com. I tried to deploy according to the file example.php but even when running example.php I get this error:
Warning: require(./vendor/autoload.php): failed to open stream: No such file or directory in /path-to/example.php on line 9
When I try to run the app from my own page then I get this error:
Parse error: syntax error, unexpected ‘use’ (T_USE) in /path-to/myfile.php on line ## – where ## is line is this:
use Helge\Loader\JsonLoader;
I am pretty sure I am missing a lot of things. Could you please enlight me a little bit? I do would like to see how your application works.
Thank you very much in advance for your help.
Which PHP version are you running on?
I am running on PHP 5.4.38. Thank you!
Oh, you just downloaded it from github, i see.
What you need to do is to go get composer: https://getcomposer.org/
then in the directory where you are working, type
composer require helgesverre/domain-availability
then in your index.php or whateverinclude 'vendor/autoload.php'
, then it should work.Hello, Helge. Thank you for your kind attention and help. I will first try to install Composer on my shared hosting account – I could tell myself that it won’t be an easy task but I am already talking with my hosting provider.
Hola, Helge! Sorry, mate, but the Composer thing is not working at all for me. I would like to try the other variant but I am not sure where I should write down this code:
{
“require”: {
“helgesverre/domain-availability”: “~0.2.0”
}
}
I mean, should I add it at the top of the example.php-like file in my working directory or should I add it somewhere else?
Thank you so very much for your kind attention and help and please, excuse my lack of knowledge for this.
What you should do is install composer on your computer, run the command then upload the vendor/ folder that it generates along with your application.
Understood. Thank you!
I am still working on customer care details but Domain Availability tool is finally working on my site:
http://www.vptica.com.ve/v1/servicios/dominios/
It is a fantastic tool and I am very grateful to you for it (;
Very nice :) Glad it worked out for you!
Hello mr.helge
i got fatal error while it run n my local host & error like this :
Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Domainav\example.php on line 9
Fatal error: require(): Failed opening required ‘vendor/autoload.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\Domainav\example.php on line 9
my code is:
Domain Availability Checker
Did you run composer?
Hi, I have installed Composer globally, and when I try to run the command:
composer -s dev helgesverre/domain-availability
I get:
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command “dev” is not defined.
Hey, my mistake, it should be composer require –dev helgesverre/domain-availability
Hi thanks for the reply. Is it supposed to be composer require –dev helgesverre/domain-availability (with 2 dashes before dev)? For some reason bth give me errors but I noticed your gitgub page has 2 dashes before dev.
The error I get when I run the command with 2 dashes is:
Your requirements could not be resolved to an installable set of packages.
Problem 1
– jeremykendall/php-domain-parser 3.0.0 requires ext-intl * -> the requested PHP extension intl is missing from your system.
– helgesverre/domain-availability 0.2.2 requires jeremykendall/php-domain-parser ^3.0 -> satisfiable by jeremykendall/php-domain-parser[3.0.0].
– Installation request for helgesverre/domain-availability ^0.2.2 -> satisfiable by helgesverre/domain-availability[0.2.2].
you need to activate the “intl” extension on your local webserver (presumably XAMPP or WAMP)
Hello, I finally managed to activate the intl extension. Now when I go to the page I have created (just uses your sample code from the ‘Usage’ section of your github page), I get the following error:
Uncaught exception ‘Exception’ with message ‘No WHOIS entry was found for that TLD’ in /Applications/XAMPP/xamppfiles/htdocs/domainChecker/vendor/helgesverre/domain-availability/src/Service/DomainAvailability.php:50 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/domainChecker/index.php(14): Helge\Service\DomainAvailability->isAvailable(‘helgesverre.com’) #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/domainChecker/vendor/helgesverre/domain-availability/src/Service/DomainAvailability.php on line 50
I am new in laravel 5. Now I want to implement domain name concept in our live project.
Using our website customers can select template and release their own website. So, for that website we want to give an option for selecting domain name for customers. That time our website will connect with namecheap site. How to do this? Can u give one idea? I am new in IT industry also..Please help me sir.
really helpful and effective way to check domain availability.
Hello Helge, I have tested your script and It works like charm.
Thank You for this powerful product.
Thanks for checking out my script, glad that it was useful to you :)
I have download from Github and i try it, but the warning show there is no file autoload.php
Warning: require(./vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\domain-availability\example.php on line 9
Fatal error: require(): Failed opening required ‘./vendor/autoload.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\domain-availability\example.php on line 9
download compreser install it, open comand line go to your projet directory (in command line) user <>
and test it again
Hello helge
could you help me please. I got fatal error after i’ve run in localhost, the error is like this :
Fatal error: Call to undefined function Pdp\idn_to_ascii() in C:\xampp\htdocs\domain-availability\vendor\jeremykendall\php-domain-parser\src\Pdp\Parser.php on line 318
thanks.
Just ignore the question above, i have found the answer from the https://github.com/HelgeSverre/Domain-Availability
Thanks for API, this is fantastic
why if i trying that i have error message, like this “Fatal error: Class ‘DomainAvailability’ not found in C:\xampp\htdocs\TA\UPDATE_4ICU\lala.php on line 35”
maybe you can help me. thanks
are you using laravel or php native?
– What does your lala.php file look like? paste it into pastebin and send me the link and I will take a look.
– Are you familiar with PSR-4 autoloading?
Hello,
Does this script still works? I clicked on the link on top to check it out but it redirects to a parked page.
Root package ‘helgesverre/domain-availability’ cannot require itself in its composer.json
Thank you for this very useful script Helge Sverre Hessevik Liseth!
Good morning Helge Sverre Hessevik Liseth !
Please i have this error <>, in fait i need to use the script in my website o allow user to chose their domain for hosting plan.
Please can you help me to understand why that error ?
What error are you getting?
My error is : WHOIS Query failed !
Did you just try to use the example code?
Yes, do not make a modification. It worked well, after a while, I started having this error message
Because WHOIS servers do rate limiting on their servers, this script will stop working if you send to many requests to their server.
If you require a mor reliable solution try to look for a commercial API like https://whoapi.com/
Hello Helge
Thanks for mentioning our service WhoAPI!
Best,
Goran
You’re welcome :)