Jump to content

Checking if a domain is available for registration


DSGameMaker

Recommended Posts

Hello Folks, I have adapted 'Mr Whois' to build an API to check if a domain is available for registration. This is the code I have so far:

 

<?php

define('COM_SERVER', 	"rs.internic.net");
define('COM_NOMATCH',	"No match");

define('NET_SERVER', 	"rs.internic.net");
define('NET_NOMATCH',	"No match");

define('ORG_SERVER',	'whois.publicinterestregistry.net');
define('ORG_NOMATCH',	'NOT FOUND');

$domain = $_GET['domain'];
$tld = $_GET['tld'];

function dispun() {
      echo "0";
}

function dispav() {
      echo "1";
}


if(ereg("^-|-$",$domain)) {
	echo "bad domain - hypen";
                exit;
}

if(!ereg("([a-z]|[A-Z]|[0-9]|-){".strlen($domain)."}",$domain)) {
	echo "bad domain";
                exit;
}

$domname = $domain . "." . $tld;

if ($tld == "com") {
                $ns = fsockopen(COM_SERVER,43); fputs($ns,"$domname\r\n");
	$result = '';
        while(!feof($ns)) $result .= fgets($ns,128); fclose($ns);
	if (eregi(COM_NOMATCH,$result)) { dispav();} else {dispun(); }
        } elseif ($tld == "net") {
	$ns = fsockopen(NET_SERVER,43); fputs($ns,"$domname\r\n");
	$result = '';
	while(!feof($ns)) $result .= fgets($ns,128); fclose($ns);
	if (eregi(NET_NOMATCH,$result)) { dispav(); } else { dispun(); }

} elseif ($tld == "org") {
	$ns = fsockopen(ORG_SERVER,43); fputs($ns,"$domname\r\n");
	$result = '';
	while(!feof($ns)) $result .= fgets($ns,128); fclose($ns);
	if (eregi(ORG_NOMATCH,$result)) { dispav(); } else { dispun(); }
}
?>

 

You just go to: test.php?domain=google&tld=com

 

Now. My problem: It seems the code can't connect to the NIC servers. I have looked through time and time again and cannot see why it is not working. I am really stuck! It would be helpful to know if it worked on another PHP installation incase my host doesn't have sockets working properly.

 

 

I am so thankful in advance.

 

 

- James

 

 

If you are using a free webhosting, most of them restrict the socket functions, such as fscokopen() and stuff like that. If that isn't the problem, you may want to double check your code, or see if those places that you go to in order to check the domain availability accept socket connections. There's probably a lot of reasons that it might not be working.

Hi, I don't use a free host. I was wondering if it worked for anyone else, that way I could identify whether it is the code or my host that is messing up.

 

BTW, it should return a 0 if the domain is unavailable and a 1 if it available when you go to test.php?domain=test&tld=com

 

 

Kind Regards

James

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.