Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查域有效性的Api_Php_Json_Api - Fatal编程技术网

Php 检查域有效性的Api

Php 检查域有效性的Api,php,json,api,Php,Json,Api,有人能告诉我一个json api,我可以用它来确认PHP脚本中域名的有效性吗?你不需要api, 您可以通过DNS查询检查域名是否确实存在 PHPcheckdnsrr-检查与给定Internet主机名或IP地址对应的DNS记录 域检查示例: <?php function validate_domain($domain){ //Check the DNS if the domain has an MX record if(checkdnsrr($domain,"MX"

有人能告诉我一个json api,我可以用它来确认PHP脚本中域名的有效性吗?

你不需要api, 您可以通过DNS查询检查域名是否确实存在

PHP
checkdnsrr
-检查与给定Internet主机名或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;
      }
}
?>

使用reg exp+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;
   }    
}
?>


参考:

您可以使用这两个功能检查网站是否有效

 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);

我该如何实现它们呢?你能把你实现的东西放在同一个位置上吗,这样我就能帮你做同样的事情了?我该如何实现它呢?调用validate_domain(“doaminame.com”),如果这个域真的存在,你就得到了true。别担心,我把它从函数中去掉,使用了if(checkdnsrr($domain,“MX”)。它可以工作。非常感谢。