DSGameMaker Posted September 21, 2008 Share Posted September 21, 2008 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 https://forums.phpfreaks.com/topic/125217-checking-if-a-domain-is-available-for-registration/ Share on other sites More sharing options...
FIREBALL5 Posted September 21, 2008 Share Posted September 21, 2008 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 https://forums.phpfreaks.com/topic/125217-checking-if-a-domain-is-available-for-registration/#findComment-647312 Share on other sites More sharing options...
DSGameMaker Posted September 22, 2008 Author Share Posted September 22, 2008 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 https://forums.phpfreaks.com/topic/125217-checking-if-a-domain-is-available-for-registration/#findComment-647507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.