- Impact
- 18
I want to be able to tell my user if a domain is available, and then if it isn't, look it up in a whois database.
I have a substancial list of whois databases, and a whois lookup script, but I just have no way of telling whether a domain is available or registered.
Here is my code already:
all the whois servers are stored in an external file in an array called "$tlds['xxx']" (eg: $tlds["co.uk"])
Thanks a lot
Tom
I have a substancial list of whois databases, and a whois lookup script, but I just have no way of telling whether a domain is available or registered.
Here is my code already:
PHP:
function get_whois($server,$domain,&$output)
{
$whois = fsockopen($server, 43);
fputs($whois, "$domain\r\n");
$result = "";
while(!feof($whois))
{
$str = fgets($whois, 1024);
$result .= $str;
if (strstr($str, "Whois Server:"))
{
$new_server = split(": ", $str);
$output = chop("$new_server[1]");
fclose($whois);
return(1);
}
}
$output = $result;
fclose($whois);
return(0);
}
include "includes/tlds.php";
if(!isset($_GET['tld'])){
$_GET['tld'] = "com";
}
if(isset($tlds[$_GET['tld']])){
$server = $tlds[$_GET['tld']];
}
else{
$server = $tlds["other"];
}
$output = "";
$Domain = $_GET['q'].".".$_GET['tld'];
// look up a domain name at rs.internic.net
$redirect = get_whois($server, $Domain, $output);
// if rs.internic.net doesn't have the information, $output will give us the
// server that does, so use it to get the registration info
while ($redirect)
{
$whois_server = $output;
$redirect = get_whois($whois_server, $Domain, $output);
}
// ouput the domain registration information
$echo = nl2br($output);
Thanks a lot
Tom






