PHP : Domain Checker Script

Monday, July 20, 2009 18:44
Posted in category PHP

this script support for malaysian domain name.

example:

  • .com.my
  • .net.my
  • .org.my
  • .gov.my
  • .edu.my
  • .my

  1. <?
  2. $domain = 'gengjawa.com.my';  ##your domain name, you can change this to accept form##
  3. ###############
  4. $whois = new whois;
  5. $result = $whois->available($domain);
  6. ###############
  7. if ($result){
  8. echo "<tr><td><br/></td></tr>";
  9. echo "<tr><td><font size='6px'>$domain,</td>&nbsp;<td><font color=green><strong>Still Available</strong></font></font></td></tr><br>";
  10. echo "<tr><td><br/><br/></td></tr>";
  11. }
  12. else{
  13. echo "<tr><td><br/></td></tr>";
  14. echo "<tr><td><font size='5px'>$domain,</td>&nbsp;<tr><td><font color=red><strong>this domain has been taken. <br />Please choose another domain</font></font></td></tr><br>";
  15. echo "<tr><td><br/><br/></td></tr>";
  16. }
  17. class whois {
  18. public $ext = array(
  19. '.com' => array('whois.crsnic.net','No match for'),
  20. '.net' => array('whois.crsnic.net','No match for'),
  21. '.org' => array('whois.publicinterestregistry.net','NOT FOUND'),
  22. '.us' => array('whois.nic.us','Not Found'),
  23. '.biz' => array('whois.biz','Not found'),
  24. '.info' => array('whois.afilias.net','NOT FOUND'),
  25. '.eu' => array('whois.eurid.eu','FREE'),
  26. '.mobi' => array('whois.dotmobiregistry.net', 'NOT FOUND'),
  27. '.tv' => array('whois.nic.tv', 'No match for'),
  28. '.in' => array('whois.inregistry.net', 'NOT FOUND'),
  29. '.co.uk' => array('whois.nic.uk','No match'),
  30. '.co.ug' => array('wawa.eahd.or.ug','No entries found'),
  31. '.or.ug' => array('wawa.eahd.or.ug','No entries found'),
  32. '.sg' => array('whois.nic.net.sg','NOMATCH'),
  33. '.com.sg' => array('whois.nic.net.sg','NOMATCH'),
  34. '.per.sg' => array('whois.nic.net.sg','NOMATCH'),
  35. '.org.sg' => array('whois.nic.net.sg','NOMATCH'),
  36. '.com.my' => array('whois.mynic.net.my','does not Exist in database'),
  37. '.net.my' => array('whois.mynic.net.my','does not Exist in database'),
  38. '.org.my' => array('whois.mynic.net.my','does not Exist in database'),
  39. '.gov.my' => array('whois.mynic.net.my','does not Exist in database'),
  40. '.edu.my' => array('whois.mynic.net.my','does not Exist in database'),
  41. '.my' => array('whois.mynic.net.my','does not Exist in database'),
  42. '.nl' => array('whois.domain-registry.nl','not a registered domain'),
  43. '.ro' => array('whois.rotld.ro','No entries found for the selected'),
  44. '.com.au' => array('whois.ausregistry.net.au','No data Found'),
  45. '.ca' => array('whois.cira.ca', 'AVAIL'),
  46. '.org.uk' => array('whois.nic.uk','No match'),
  47. '.name' => array('whois.nic.name','No match'),
  48. '.ac.ug' => array('wawa.eahd.or.ug','No entries found'),
  49. '.ne.ug' => array('wawa.eahd.or.ug','No entries found'),
  50. '.sc.ug' => array('wawa.eahd.or.ug','No entries found'),
  51. '.ws' => array('whois.website.ws','No Match'),
  52. '.be' => array('whois.ripe.net','No entries'),
  53. '.com.cn' => array('whois.cnnic.cn','no matching record'),
  54. '.net.cn' => array('whois.cnnic.cn','no matching record'),
  55. '.org.cn' => array('whois.cnnic.cn','no matching record'),
  56. '.no' => array('whois.norid.no','no matches'),
  57. '.se' => array('whois.nic-se.se','No data found'),
  58. '.nu' => array('whois.nic.nu','NO MATCH for'),
  59. '.com.tw' => array('whois.twnic.net','No such Domain Name'),
  60. '.net.tw' => array('whois.twnic.net','No such Domain Name'),
  61. '.org.tw' => array('whois.twnic.net','No such Domain Name'),
  62. '.cc' => array('whois.nic.cc','No match'),
  63. '.nl' => array('whois.domain-registry.nl','is free'),
  64. '.pl' => array('whois.dns.pl','No information about'),
  65. '.pt' => array('whois.dns.pt','No match')
  66. );
  67. public $error;
  68. function available($domain){
  69. $domain = trim($domain);
  70. if (eregi('^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$',$domain) != 1){
  71. $error = 'Invalid domain (Letters, numbers and hypens only) ('.$domain.')';
  72. return false;
  73. }
  74. preg_match('@^(http://www\.|http://|www\.)?([^/]+)@i', $domain, $preg_metch_result);
  75. $f_result = ";
  76. $domain = $preg_metch_result[2];
  77. $domain_name_array = explode('.', $domain);
  78. $domain_domain = strtolower(trim($domain_name_array[count($domain_name_array)-1]));
  79. $ext_in_list = false;
  80. if (array_key_exists('.'.$domain_domain, $this->ext)){
  81. $ext_in_list = true;
  82. }
  83. if(strlen($domain) > 0 && $ext_in_list){
  84. $server = ";
  85. $server = $this->ext['.' .$domain_domain][0];
  86. $lookup_result = gethostbyname($server);
  87. if ($lookup_result == $server){
  88. $error = 'Error: Invalid extension &#8211; '.$domain_domain.'. / server has outgoing connections blocked to '.$server.'.';
  89. return false;
  90. }
  91. $fs = fsockopen($server, 43,$errno,$errstr,10);
  92. if (!$fs || ($errstr != "")){
  93. $error = 'Error: ('.$server.') '.$errstr.' ('.$errno.')';
  94. return false;
  95. }
  96. fputs($fs, "$domain\r\n");
  97. while( !feof($fs) ) {
  98. $f_result .= fgets($fs,128);
  99. }
  100. fclose($fs);
  101. if($domain_domain == 'org'){
  102. nl2br($f_result);
  103. }
  104. if(eregi($this->ext['.'.$domain_domain][1], $f_result)){
  105. return true;
  106. } else {
  107. return false;
  108. }
  109. } else {
  110. $error = 'Invalid Domain and/or TLD server entry does not exist';
  111. }
  112. return false;
  113. }
  114. }
  115. ?>
You can skip to the end and leave a response. Pinging is currently not allowed.
Tags: , ,

2 Responses to “PHP : Domain Checker Script”

  1. How I Lost 30 Pounds in 30 Days Without Diet says:

    July 24th, 2009 at 8:22 PM

    Thanks for posting about this, I would love to read more about this topic.

  2. Host2Serve says:

    November 4th, 2009 at 2:58 AM

    i think should be like this ‘does not exist in database’

    exist should be lowercase

Leave a Reply