KKPeters
asked on
PHP Domain availability check
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.8 088.ORG
MICROSOFT.COM.RAWKZ.MUH.WE RLD.MENTAL FLOSS.CA
MICROSOFT.COM.OHMYGODITBUR NS.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.
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.8
MICROSOFT.COM.RAWKZ.MUH.WE
MICROSOFT.COM.OHMYGODITBUR
So, I'm guessing if someone searched for example.com and someone else was using example.com.another-domain
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.
ASKER
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?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"[^>]*>
// 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