We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

PHP Domain availability check

KKPeters
KKPeters asked
on
Medium Priority
736 Views
Last Modified: 2012-08-14
Hi all,

I'm tinkering with a script to let people see if a domain is available to register or not.

The best way I've found so far is to use a whois script and then see if the response includes the words "Not found". I've had success with the one from here (near bottom):

http://www.webhostingtalk.com/showthread.php?threadid=231463

Except I have the problem that it matches too generally, if I search for "microsoft.com" I get lots of jokes like:

MICROSOFT.COM.RUNS.ON.AN.8088.ORG
MICROSOFT.COM.RAWKZ.MUH.WERLD.MENTALFLOSS.CA
MICROSOFT.COM.OHMYGODITBURNS.COM

So, I'm guessing if someone searched for example.com and someone else was using example.com.another-domain.com it's going to return that and my script, not finding a "Not found" message will claim the domain is taken even if example.com is in fact free.

Any suggestions? Is there a way I can stop matching these sub domains or does someone have a suggestion for a better script altogether? I mean, I don't need whois info, only a Yes or No when it comes to is a domain free or not.
Comment
Watch Question

Go to http://www.enom.com/resellers/default.asp?step=1#step1 and sign up for a free resellers account.  You can then use your login/pass to check domain name availability using this script I made:

<?php

// domain check via CURL:

$sld = $_POST['sld'];
$tld = $_POST['tld'];
$url = "http://reseller.enom.com/interface.asp?uid=YOURUIDHERE&pw=YOURPASSHERE&command=check&sld=$sld&tld=$tld&responsetype=text";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTP_VERSION, 1.0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// grab URL and pass it to the browser
$serveroutput = curl_exec($ch);
$serveroutput = preg_replace('/(?s)<meta http-equiv="Expires"[^>]*>/i', '', $serveroutput);

// close curl resource, and free up system resources
curl_close($ch);
echo "$extpage\n\n\n";

// watch the magic happen
$myarray = array();
$ex = explode("\n",$serveroutput);
foreach ($ex as $value) {
      if ($pos = strpos($value,"=")) {
            $mykey = substr($value, 0, $pos);
            $myvalue = substr($value, $pos+1);
            $myarray = $myarray + array($mykey => $myvalue);
      }
}
extract($myarray);

echo "<pre>";
print_r ($myarray);

?>

It will return something like:
    [RRPCode] => 211
    [RRPText] => Domain name not available
And you can just check if ($RRPCode==211), or if ($RRPText == "Domain name not available").

This script requires the CURL package to be installed and compiled with PHP.
http://www.php.net/manual/en/ref.curl.php

You can also use sockets, but I recommend the CURL method.
http://www.php.net/manual/en/ref.sockets.php

Author

Commented:
That's great thanks, but if possible I'd prefer not to rely on someone elses service. Just incase they pull the plug or change the way it works, etc.

I'll use it there's no other alternative, but it just seem like I can't be the only person to have wanted to try this!
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.