2009-06-05 5 views
0

이 스크립트를 올바르게 작동시키지 못했습니다. 도메인을 전달하려고하면 cnn.com에서도 항상 AVAILABLE을 반환합니다! $ message는 내가 확인할 수있는 도메인의 이름입니다.도메인 기능이 작동하지 않는지 확인하는 PHP 함수

이것은 함수 호출입니다.

include("domain.class.php"); 

// Initializing class 
$domain=new domain("$message"); 

// Checking if domain is available 
if($domain->is_available()){ 
$status = "$message is available"; 
}else{ 
$status = "$message is unavailable"; 
echo = $status; 
} 

그리고 domain.class.php입니다.

<? 
class domain{ 
var $domain=""; 
var $servers=array(
array("com","whois.geektools.com","No match"), 
    array("net","whois.geektools.com","No match"), 
     array("org","whois.geektools.com","No match"), 
); 



var $idn=array(224,225,226,227,228,229,230,231,232,233,234,235,240,236,237,238,239,241,242,243,244,245,246,248,254,249,250,251,252,253,255); 
// var $idn=array("00E0","00E1","00E2","00E3","00E4","00E5","0101","0103","0105","00E6","00E7","0107","0109","010B","010D","010F","0111","00E8","00E9","00EA","00EB","0113","0115","0117","0119","011B","014B","00F0","011D","011F","0121","0123","0125","0127","00EC","00ED","00EE","00EF","0129","012B","012D","012F","0131","0135","0137","0138","013A","013C","013E","0142","00F1","0144","0146","0148","00F2","00F3","00F4","00F5","00F6","00F8","014D","014F","0151","0153","0155","0157","0159","015B","015D","015F","0161","0163","0165","0167","00FE","00F9","00FA","00FB","00FC","0169","016B","016D","016F","0171","0173","0175","00FD","00FF","0177","017A","017C","017E"); 

function domain($str_domainname){ 
    $this->domain=$str_domainname; 
} 

function info(){ 
    if($this->is_valid()){ 

     $tldname=$this->get_tld(); 
     $domainname=$this->get_domain(); 
     $whois_server=$this->get_whois_server(); 

     if($whois_server!=""){ 
      $fp = fsockopen($whois_server,43); 

      $dom=$domainname.".".$tldname; 
//    fputs($fp, "$dom\r\n"); 

      // New IDN 
      if($tldname=="de") { 
       fputs($fp, "-C ISO-8859-1 -T dn $dom\r\n"); 
      } else { 
       fputs($fp, "$dom\r\n"); 
      } 

      // Getting string 
      $string=""; 

      // Checking whois server for .com and .net 
      if($tldname=="com" || $tldname=="net" || $tldname=="edu"){ 
       while(!feof($fp)){ 
        $line=trim(fgets($fp,128)); 

        $string.=$line; 

        $lineArr=split(":",$line); 

        if(strtolower($lineArr[0])=="whois server"){ 
         $whois_server=trim($lineArr[1]); 
        } 
       } 
       // Getting whois information 
       $fp = fsockopen($whois_server,43); 

       $dom=$domainname.".".$tldname; 
       fputs($fp, "$dom\r\n"); 

       // Getting string 
       $string=""; 

       while(!feof($fp)){ 
        $string.=fgets($fp,128); 
       } 

       // Checking for other tld's 
      }else{ 
       while(!feof($fp)){ 
        $string.=fgets($fp,128); 
       } 
      } 
      fclose($fp); 

      return $string; 
     }else{ 
      return "No whois server for this tld in list!"; 
     } 
    }else{ 
     return "Domainname isn't valid!"; 
    } 
} 

/** 
* Returns the whois data of the domain in HTML format 
* @return string $whoisdata Whois data as string in HTML 
* @desc Returns the whois data of the domain in HTML format 
*/ 
function html_info(){ 
    return nl2br($this->info()); 
} 

/** 
* Returns name of the whois server of the tld 
* @return string $server the whois servers hostname 
* @desc Returns name of the whois server of the tld 
*/ 
function get_whois_server(){ 
    $found=false; 
    $tldname=$this->get_tld(); 
    for($i=0;$i<count($this->servers);$i++){ 
     if($this->servers[$i][0]==$tldname){ 
      $server=$this->servers[$i][1]; 
      $full_dom=$this->servers[$i][3]; 
      $found=true; 
     } 
    } 
    return $server; 
} 

/** 
* Returns the tld of the domain without domain name 
* @return string $tldname the tlds name without domain name 
* @desc Returns the tld of the domain without domain name 
*/ 
function get_tld(){ 
    // Splitting domainname 
    $domain=split("\.",$this->domain); 
    if(count($domain)>2){ 
     $domainname=$domain[0]; 
     for($i=1;$i<count($domain);$i++){ 
      if($i==1){ 
       $tldname=$domain[$i]; 
      }else{ 
       $tldname.=".".$domain[$i]; 
      } 
     } 
    }else{ 
     $domainname=$domain[0]; 
     $tldname=$domain[1]; 
    } 
    return $tldname; 
} 


/** 
* Returns all tlds which are supported by the class 
* @return array $tlds all tlds as array 
* @desc Returns all tlds which are supported by the class 
*/ 
function get_tlds(){ 
    $tlds=""; 
    for($i=0;$i<count($this->servers);$i++){ 
     $tlds[$i]=$this->servers[$i][0]; 
    } 
    return $tlds; 
} 

/** 
* Returns the name of the domain without tld 
* @return string $domain the domains name without tld name 
* @desc Returns the name of the domain without tld 
*/ 
function get_domain(){ 
    // Splitting domainname 
    $domain=split("\.",$this->domain); 
    return $domain[0]; 
} 

/** 
* Returns the full domain 
* @return string $fulldomain 
* @desc Returns the full domain 
*/ 
function get_fulldomain(){ 
    return $this->domain; 
} 

/** 
* Returns the string which will be returned by the whois server of the tld if a domain is avalable 
* @return string $notfound the string which will be returned by the whois server of the tld if a domain is avalable 
* @desc Returns the string which will be returned by the whois server of the tld if a domain is avalable 
*/ 
function get_notfound_string(){ 
    $found=false; 
    $tldname=$this->get_tld(); 
    for($i=0;$i<count($this->servers);$i++){ 
     if($this->servers[$i][0]==$tldname){ 
      $notfound=$this->servers[$i][2]; 
     } 
    } 
    return $notfound; 
} 

/** 
* Returns if the domain is available for registering 
* @return boolean $is_available Returns 1 if domain is available and 0 if domain isn't available 
* @desc Returns if the domain is available for registering 
*/ 
function is_available(){ 
    $whois_string=$this->info(); // Gets the entire WHOIS query from registrar 
    $not_found_string=$this->get_notfound_string(); // Gets 3rd item from array 
    $domain=$this->domain; // Gets current domain being queried 

    [email protected]_replace("$domain","",$whois_string); 

    $whois_string [email protected]_replace("/\s+/"," ",$whois_string); //Replace whitespace with single space 

    $array=split(":",$not_found_string); 

    if($array[0]=="MAXCHARS"){ 
     if(strlen($whois_string2)<=$array[1]){ 
      return true; 
     }else{ 
      return false; 
     } 
    }else{ 
     if(preg_match("/".$not_found_string."/i",$whois_string)){ 
      return true; 
     }else{ 
      return false; 
     } 
    } 
} 

function get_cn_server($whois_text){ 

} 


/** 
* Returns if the domain name is valid 
* @return boolean $is_valid Returns 1 if domain is valid and 0 if domain isn't valid 
* @desc Returns if the domain name is valid 
*/ 
function is_valid(){ 

    $domainArr=split("\.",$this->domain); 

    // If it's a tld with two Strings (like co.uk) 
    if(count($domainArr)==3){ 

     $tld=$domainArr[1].".".$domainArr[2]; 
     $found=false; 

     for($i=0;$i<count($this->servers) && $found==false;$i++){ 
      if($this->servers[$i][0]==$tld){ 
       $found=true; 
      } 
     } 
     if(!$found){ 
      return false; 
     } 

    }else if(count($domainArr)>3){ 
     return false; 
    } 

    // Creating regular expression for 
    if($this->get_tld()=="de"){ 
     for($i=0;$i<count($this->idn);$i++){ 
      $idn.=chr($this->idn[$i]); 
      // $idn.="\x".$this->idn[$i].""; 
     } 
     $pattern="^[a-z".$idn."0-9\-]{3,}$"; 
    }else{ 
     $pattern="^[a-z0-9\-]{3,}$"; 
    } 

    if(ereg($pattern,strtolower($this->get_domain())) && !ereg("^-|-$",strtolower($this->get_domain())) && !preg_match("/--/",strtolower($this->get_domain()))){ 
     return true; 
    }else{ 
     return false; 
    } 
} 
} 
?> 

필자는이 이상 공부하고 잠시 다른 일을 시도하고있다. 누군가가 올바른 방향으로 나를 가리킬 수 있을까요? 이드는 여기서 무엇이 빠졌는지 배우는 것을 좋아합니다.

+0

당신이 당신이 가진, 코드 250 개 + 라인을 게시하려고하는 경우 디버깅에 얼마나 노력했는지 설명하고 있습니다. 귀하의 코드를 추적하고 당신이 고투하고있는 힌트를 - 정규식입니까?, whois 프로토콜입니까? –

답변

2

나는 domain.class.php에서 적어도 두 가지 방법으로 문제를 격리했다. 다음은 빠른 수정입니다.

도메인 유효성 검사를 데려가 :

function is_valid(){ //because this always returns false 
    return true; 

또한, get_whois_server() 항상 아무 것도 반환하지 않습니다. "정보 없음"에 자신의 번호 일치 문자열을 변경 whois.geektools.com

function get_whois_server(){ 
    return "whois.geektools.com"; //the whois server declared in the class does work 

마지막으로, 그리고 도메인 사용할 수 때 우리가 알고 어떻게이다 : 그래서 우리는 즉, get_whois_server()에서 리터럴 문자열을 반환합니다. 에 클래스의 시작 부분에 배열을 변경 : 다음

array("com","whois.geektools.com","no information"), //No match to "no information" 
     array("net","whois.geektools.com","No match"), 
       array("org","whois.geektools.com","No match"), 
); 

예상대로 :

$domain = new domain("google.com"); //make sure to leave out http:// and www 
if(.... 
    .... 
//Returns "is unavailable"; 

그리고

$domain = new domain("jsdhfsdfkljsadhjds.com"); //make sure to leave out http:// and www 
if(.... 
    .... 
//Returns "is available"; 
관련 문제