2016-07-06 3 views

답변

2

api가 필요하지 않은 경우 도메인 이름이 실제로 존재하는지 여부는 DNS 쿼리를 통해 확인할 수 있습니다.

PHP checkdnsrr - 주어진 인터넷 호스트 이름 또는 IP 주소 도메인 확인의

예에 해당하는 DNS 레코드 확인 : 등록 특급과 이메일 확인의

<?php 
function validate_domain($domain){ 

     //Check the DNS if the domain has an MX record 
     if(checkdnsrr($domain,"MX")){ 
     return true; 
     }else{ 
     return false; 
     } 
} 
?> 

예를 + DNS는

<?php 
function validate_email($email){ 

    $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$"; 

    if(eregi($exp,$email)){ 

     if(checkdnsrr(array_pop(explode("@",$email)),"MX")){ 
     return true; 
     }else{ 
     return false; 
     } 

    }else{ 

     return false; 
    }  
} 
?> 
을 확인

ref :

+0

그럼 어떻게 구현할 수 있습니까? – Jez

+0

validate_domain ("doaminname.com")을 호출하고 도메인이 실제로 존재하면 true가됩니다. –

+1

작동하지 않는 if (checkdnsrr ($ domain, "MX"))를 사용하여 걱정하지 마십시오. 고맙습니다. – Jez

0

이 두 기능을 사용하여 웹 사이트가 유효한지 여부를 확인할 수 있습니다.

function is_website_valid() { 
    if ($headers && (@$headers[0]=='HTTP/1.0 404 Not Found' || @$headers[1]=='HTTP/1.0 404 Not Found')) { 
     return 'invalid'; 
    } 
    elseif (!is_array($headers)) { 
     return 'invalid'; 
    } 
    else { 
     return 'valid'; 
    } 
} 
function get_website_headers($website) { 
    ini_set("user_agent", "Mozilla custom agent"); 
    $headers = get_headers($website, 1); 
    return $headers; 
} 
$status = array('website'=>$website,'status'=>is_website_valid()); 
echo json_encode($status); 
+0

그리고 어떻게 구현합니까? – Jez

+0

동일하게 구현 한 것을 넣을 수 있으므로 동일한 도움이 될 수 있습니다. –

관련 문제