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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.