PDA

View Full Version : Checking Domain Availability with PHP



The Stranger
November 17th, 2006, 09:07 AM
Hi guys! I'm having some trouble making a script to check a domain's availability... Here's what I got:



$fp = fsockopen("whois.opensrs.net",43);
fputs($fp,$domain_name);
while(!feof($fp)) {
echo fgets($fp,1048);
echo "<br />";
} //while
fclose($fp);
That just tell me the "whois" info, and that's fine but I want to refine the results to: "It's availabe" and "Sorry, it's taken". Any Ideas will be appreciated!

skrolikowski
November 17th, 2006, 11:21 PM
What happens if there is no "whois" result?

You could try this:


if(!$fp){
echo "Sorry, it's taken";
} else {
echo "It's available";
}

The Stranger
November 18th, 2006, 11:11 PM
mmhhh... That's not working because "$fp" it's always true, even if the domain it's not availble, but thanks!

hl
November 19th, 2006, 07:31 PM
What does it return if the domain isn't available?

edit:/ It returns Can't get information on non-local domain strtoupper($domain_name)

So basically you want to check your reading.


$fp = fsockopen("whois.opensrs.net",43);
fputs($fp,$domain_name);
while(!feof($fp)) {
$whois_info .= fgets($fp,1048);
$whois_info .= "<br />";
}
if(substr($whois_info, 0, 41) == "Can't get information on non-local domain"){
echo strtoupper($domain_name) . " is AVAILABLE!";
}
else{
echo strtoupper($domain_name) . " is TAKEN! <br />";
echo $whois_info;
}
fclose($fp);

Try that on.