:::: MENU ::::

Domain Availability

Background – Checking Domain Availability

A few client’s were looking to expand their internet empire, hoping to automate a process to check domain availability. I put together the below script which would do just that for them. It uses the whois servers from who.is, and makes a simple cURL GET request. The response is then parsed for the text, “appears to be available”, and the response is returned. Use as you see fit.

The below is now being released under GPLv2.

The Code

function domainAvailability($domain, $tld){
	$ch = curl_init("http://who.is/whois/$domain.$tld/");
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_POST, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			
	$output = curl_exec($ch);      
	curl_close($ch);
			
	if(strstr($output, 'appears to be available')){
		return true;	
	}
			
	return false;
}
	   
echo "Checking highonphp.com... ". (domainAvailability('highonphp', 'com') ? 'Available' : 'Taken')."n";
echo "Checking highonphp.net... ". (domainAvailability('highonphp', 'net') ? 'Available' : 'Taken')."n";

Explanation

The above code does the following:

  • Step 1: Supply domain and tld
  • Step 2: Make cURL request to who.is
  • Step 3: Search response for ‘appears to be available’
  • Step 4: Return true or false

Disclaimer: Who.is has spam prevention detection enabled on their site. We are not affiliated with who.is and do not encourage abuse of the above script.


One Comment

  • Reply Torri Mastrocovi |

    I believe everything posted made a lot of sense. However, what about this? what if you added a little content? I ain’t suggesting your content isn’t solid, however suppose you added a title that makes people desire more? I mean PHP: Domain Availability High On PHP is kinda vanilla. You could peek at Yahoo’s home page and note how they write article headlines to grab people interested. You might add a related video or a picture or two to get people interested about what you’ve written. In my opinion, it would bring your website a little bit more interesting.

So, what do you think ?

  • *