/include/domain-age-functions.php

https://github.com/ngocphong1991/buylink · PHP · 198 lines · 165 code · 27 blank · 6 comment · 22 complexity · 52c8bfeda46634c04766f98a4458aa11 MD5 · raw file

  1. <?php
  2. //@ function check VietNam Domain Age
  3. //@ Return timestamp
  4. //$domain_age = getDomainAge('cab.vn');
  5. //echo timeAgo($domain_age);
  6. function getDomainName($domain, $type='ext'){
  7. $true = getTrueDomain($domain);
  8. $temparray=explode('.',trim($true,"www."));
  9. $domain=array_shift($temparray);
  10. $domainExt=join('.',$temparray);
  11. $domainExt_arr = explode("/", $domainExt);
  12. if($type=='ext') return ".".$domainExt_arr[0];
  13. else return $domain.".".$domainExt_arr[0];;
  14. }
  15. function updateDomainAge($domain_age,$pid){
  16. $res = mysql_query('' . 'update `publishersinfo` set `domain_age`=\'' . $domain_age . '\' where uid=\'' . $_SESSION['uid'] . '\' and pid=\'' . $pid. '\'');
  17. return $res;
  18. }
  19. function getTrueDomain($domain){
  20. $des = array("", "", "", "");
  21. $from = array("http://", "https://", "http://www.", "https://www.");
  22. $tru_domain = str_replace($from, $des, $domain);
  23. return $tru_domain;
  24. }
  25. function getVNDomain($domain, $type="noxml"){
  26. if($type=='xml'){
  27. $doc = new DOMDocument();
  28. $doc->load( 'http://www.matbao.net/whoisXML.aspx?domain='.trim($domain).'' );
  29. $description = $doc->getElementsByTagName("item");
  30. foreach( $description as $key=> $employee )
  31. {
  32. $names = $employee->getElementsByTagName( "description" );
  33. $vnDomainAge = $names->item(0)->nodeValue;
  34. }
  35. }
  36. else
  37. {
  38. $vnDomainAge = get_web_page("http://www.pavietnam.vn/vn/whois.php?cmd=getwhois&domain=".trim($domain)."");
  39. //$vnDomainAge = get_web_page("http://www.matbao.net/RWhois.aspx?Domain=".trim($domain)."");
  40. }
  41. if(!$vnDomainAge) return 0;
  42. $vnDomainAge=substr($vnDomainAge,strpos($vnDomainAge,'Issue Date :')+strlen('Issue Date :'));
  43. if($vnDomainAge === false){} else{
  44. $vnDomainAge=substr($vnDomainAge,0,strpos($vnDomainAge,'Expired Date :'));
  45. }
  46. $vnDomainAge = strip_tags($vnDomainAge);
  47. $date = explode('/', trim($vnDomainAge));
  48. $D = $date[0];
  49. $M = $date[1];
  50. $Y = $date[2];
  51. $dobshow = $M."/".$D."/".$Y;
  52. $vnDomainAge = strtotime($dobshow);
  53. return trim($vnDomainAge);
  54. }
  55. function getDomainAge($domain, $type) {
  56. $domain = getTrueDomain($domain);
  57. $domain = getDomainName($domain,'domain');
  58. $domainAge = new DomainAge();
  59. return trim($domainAge->age($domain));
  60. }
  61. function getOtherDomain($domain){
  62. $result = get_web_page("http://www.domainageonline.com/process_tool.php?domain=".$domain."");
  63. $domain_age=substr($result,strpos($result,'first registered on <strong>')+strlen('first registered on <strong>'));
  64. $domain_age=substr($domain_age,0,strpos($domain_age,'</strong>'));
  65. //$domain_age = strtotime(trim($domain_age));
  66. if(!$domain_age){
  67. $result = whois::lookup($domain);
  68. if(strstr($result, " No match")){
  69. $domain_age = 0;
  70. }else{
  71. $domain_age=substr($result,strpos($result,'Creation Date:')+strlen('Creation Date:'));
  72. if($domain_age === false){} else{
  73. $domain_age=substr($domain_age,0,strpos($domain_age,'Expiration Date: '));
  74. }
  75. }
  76. $domain_age = strip_tags($domain_age);
  77. unset($result);
  78. }
  79. $domain_age = strtotime(trim($domain_age));
  80. return $domain_age;
  81. }
  82. class whois
  83. {
  84. const timeout = 30;
  85. const whoishost = 'whois.internic.net';
  86. public static function lookup($domain){
  87. $result = "";
  88. $errno = 0;
  89. $errstr='';
  90. $fd = fsockopen(whois::whoishost,43, $errno, $errstr, whois::timeout);
  91. if ($fd){
  92. fputs($fd, $domain."\015\012");
  93. while (!feof($fd)) {
  94. $result .= fgets($fd,128) . "<br />";
  95. }
  96. fclose($fd);
  97. }
  98. return $result;
  99. }
  100. }
  101. class DomainAge{
  102. private $WHOIS_SERVERS=array(
  103. "com" => array("whois.verisign-grs.com","/Creation Date:(.*)/"),
  104. "net" => array("whois.verisign-grs.com","/Creation Date:(.*)/"),
  105. "org" => array("whois.pir.org","/Created On:(.*)/"),
  106. "info" => array("whois.afilias.info","/Created On:(.*)/"),
  107. "biz" => array("whois.neulevel.biz","/Domain Registration Date:(.*)/"),
  108. "us" => array("whois.nic.us","/Domain Registration Date:(.*)/"),
  109. "uk" => array("whois.nic.uk","/Registered on:(.*)/"),
  110. "ca" => array("whois.cira.ca","/Creation date:(.*)/"),
  111. "tel" => array("whois.nic.tel","/Domain Registration Date:(.*)/"),
  112. "ie" => array("whois.iedr.ie","/registration:(.*)/"),
  113. "it" => array("whois.nic.it","/Created:(.*)/"),
  114. "cc" => array("whois.nic.cc","/Creation Date:(.*)/"),
  115. "ws" => array("whois.nic.ws","/Domain Created:(.*)/"),
  116. "sc" => array("whois2.afilias-grs.net","/Created On:(.*)/"),
  117. "mobi" => array("whois.dotmobiregistry.net","/Created On:(.*)/"),
  118. "pro" => array("whois.registrypro.pro","/Created On:(.*)/"),
  119. "edu" => array("whois.educause.net","/Domain record activated:(.*)/"),
  120. "tv" => array("whois.nic.tv","/Creation Date:(.*)/"),
  121. "travel" => array("whois.nic.travel","/Domain Registration Date:(.*)/"),
  122. "in" => array("whois.inregistry.net","/Created On:(.*)/"),
  123. "me" => array("whois.nic.me","/Domain Create Date:(.*)/"),
  124. "cn" => array("whois.cnnic.cn","/Registration Date:(.*)/"),
  125. "asia" => array("whois.nic.asia","/Domain Create Date:(.*)/"),
  126. "ro" => array("whois.rotld.ro","/Registered On:(.*)/"),
  127. "aero" => array("whois.aero","/Created On:(.*)/"),
  128. "nu" => array("whois.nic.nu","/created:(.*)/"),
  129. "vn" => array("whois.net.vn","/Issue Date :(.*)/"),
  130. );
  131. public function age($domain)
  132. {
  133. $domain = trim($domain); //remove space from start and end of domain
  134. if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7); // remove http:// if included
  135. if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);//remove www from domain
  136. if(preg_match("/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i",$domain))
  137. {
  138. $domain_parts = explode(".", $domain);
  139. $tld = strtolower(array_pop($domain_parts));
  140. if(!$server=$this->WHOIS_SERVERS[$tld][0]) {
  141. return false;
  142. }
  143. if($tld == 'vn') $res = file_get_contents("http://www.whois.net.vn/whois.php?domain=$domain&act=getwhois");
  144. else $res=$this->queryWhois($server,$domain);
  145. if(preg_match($this->WHOIS_SERVERS[$tld][1],$res,$match))
  146. {
  147. if(count(explode('/', $match[1]))) $match[1] = trim(str_replace('<br>','',str_replace('/', '-', $match[1])));
  148. date_default_timezone_set('UTC');
  149. return strtotime($match[1]);
  150. }
  151. else
  152. return false;
  153. }
  154. else
  155. return false;
  156. }
  157. private function queryWhois($server,$domain)
  158. {
  159. $fp = @fsockopen($server, 43, $errno, $errstr, 20) or die("Socket Error " . $errno . " - " . $errstr);
  160. if($server=="whois.verisign-grs.com")
  161. $domain="=".$domain;
  162. fputs($fp, $domain . "\r\n");
  163. $out = "";
  164. while(!feof($fp)){
  165. $out .= fgets($fp);
  166. }
  167. fclose($fp);
  168. return $out;
  169. }
  170. }
  171. ?>