Kod Savas improved


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. class Randomainer {
  4.  
  5. private static $checkedUrls = array(); // this array contains URL who is already checked.
  6. private static $savePath = '/'; // The path where the log must be saved.
  7. public $maxDomain = 10; // for security and performance issues is this a temporary solution..
  8.  
  9. public $characters = array( // possible charachters
  10. 'a', 'b', 'c', 'd', 'e', 'f',
  11. 'g', 'h', 'i', 'j', 'k', 'l',
  12. 'm', 'n', 'o', 'p', 'q', 'r',
  13. 's', 't', 'u', 'v', 'w', 'x',
  14. 'y', 'z', '0', '1', '2', '3',
  15. '4', '5', '6', '7', '8', '9',
  16. '-'
  17. );
  18.  
  19. private static $tlds = array( // all Top-Level Domain Extensions
  20. 'aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi',
  21. 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'ac', 'ad', 'ae', 'af', 'ag', 'ai', 'al',
  22. 'am', 'an', 'ao', 'aq', 'ar', 'as', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd' ,'be', 'bf', 'bg',
  23. 'bh', 'bi', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by' ,'bz', 'ca', 'cc' ,'cd', 'cf',
  24. 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'cz', 'de', 'dj', 'dk',
  25. 'dm', 'do', 'dz', 'ec', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb',
  26. 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk',
  27. 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo',
  28. 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr',
  29. 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mk', 'ml', 'mn', 'mn', 'mo', 'mp', 'mr',
  30. 'ms', 'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'nc', 'ne', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr',
  31. 'nu', 'nz', 'nom', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'ps', 'pt', 'pw', 'py', 'qa',
  32. 're', 'ra', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sj', 'sk', 'sl', 'sm',
  33. 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn',
  34. 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi',
  35. 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zw', 'arpa',
  36. 'local'
  37. );
  38.  
  39.  
  40. public function generateDomainName($extensions)
  41. {
  42. // generate a domain name with all chars and selected domain extensions
  43. $counter = 0;
  44. foreach($this->characters as $first)
  45. {
  46. foreach($this->characters as $second)
  47. {
  48. foreach($this->characters as $third)
  49. {
  50. foreach($extensions as $ext)
  51. {
  52. if(($first != '-' && $third != '-')
  53. && in_array($ext, self::$tlds)) // the first and last character may not be - and the domain extension must be allowed.
  54. {
  55. $domain = $first.$second.$third.'.'.$ext; // build domain name
  56. $this->checkDomainName($domain);
  57. $counter = $counter +1;
  58. if($counter >= $this->maxDomain)// If all is good, we exit from here.
  59. {
  60. return 0;
  61. }
  62. }
  63. }//end extension foreach
  64. }//end third foreach
  65. }// end second foreach
  66. }// end first foreach
  67.  
  68. }
  69.  
  70. public function checkDomainName($url)
  71. {
  72. // redefine
  73. $domain = $url;
  74. $xml = new DOMDocument('1.0', 'utf-8');
  75. $xml->load('http://whoiswebservice.org/whois.asmx/IsDomainAvailable?website='.$domain);
  76. $result = $xml->getElementsByTagName('string')->item(0)->nodeValue;
  77.  
  78. self::$checkedUrls[$domain] = $result;
  79. }
  80.  
  81. public function getAvailableDomains()
  82. {
  83. $return = array();
  84. foreach(self::$checkedUrls as $domain => $status)
  85. {
  86. if($status == '1')
  87. {
  88. $return[] = $domain;
  89. }//end if status checking
  90. } // end foreach checkedurls
  91.  
  92. return $return; // return the array who contains the avalaible domains
  93. }
  94.  
  95. public function getTlds()
  96. {
  97. return self::$tlds;
  98. }
  99. /**
  100. * This method will save the results in a log file
  101. * @return void
  102. */
  103. public function save()
  104. {
  105. // method to save the results.
  106. $checkedDomains = self::$checkedUrls;
  107. $file = fopen('log-'.time().'.txt', 'a+'); // log dosyasini acalim, eger yok ise (Ki yok.. yenisini olusturalim.)
  108. foreach($checkedDomains as $domain => $status)
  109. {
  110. if($status == '1')
  111. {
  112. $text = "Domain: ".$domain." is available.\n";
  113. }else{
  114. $text = "Domain: ".$domain." is not available.\n";
  115. }
  116. fwrite($file, $text);
  117. }// end foreach checked domains
  118. fclose($file); // actigimiz log dosyasini kapatalim..
  119. }
  120. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.