Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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 checkdnsrr()函数未给出预期结果_Php_Function - Fatal编程技术网

PHP checkdnsrr()函数未给出预期结果

PHP checkdnsrr()函数未给出预期结果,php,function,Php,Function,我在PHP中尝试使用checkdnsrr()函数来测试给定的主机名是否有效 下面是PHP代码: $url = "this_is_a_wrong_url.com"; if (checkdnsrr($url, 'A')) { echo "Domain exists."; } else { echo "Domain doesnot exists."; } 但即使对于无效的url,它也会返回true 我做错了什么?我使用的是PHP5.3.5 编辑:此代码在具有相同PHP版本的Lin

我在PHP中尝试使用checkdnsrr()函数来测试给定的主机名是否有效

下面是PHP代码:

$url = "this_is_a_wrong_url.com";
if (checkdnsrr($url, 'A')) 
{
    echo "Domain exists.";
}
else
{
     echo "Domain doesnot exists.";
}
但即使对于无效的url,它也会返回true

我做错了什么?我使用的是PHP5.3.5

编辑:此代码在具有相同PHP版本的Linux机器上运行良好。它仅在Windows计算机上给出无效结果。

请尝试此操作

 $url = "this_is_a_wrong_url.com";
    if(checkdnsrr(($url),"A"))
{
    echo "Domain exists.";
}
else
{
     echo "Domain doesnot exists.";
}

因此,brakets中的
$url
一些ISP会将无效域重定向到自己的搜索服务器。时代华纳/路行者就是这样一家ISP。您的代码工作正常,但您可能需要检查以确保它们不会解析到ISP的搜索服务器。首先使用gethostbyname检查无效域,然后使用该域进行检查

if (checkdnsrr($url, 'A') && gethostbyname($url) != '204.232.137.207' && gethostbyname($url) !='66.152.109.110')
或者更好的是

if(checkdnsrr($url,'A') && !in_array(gethostbyname($url),gethostbynamel('this_is_a_wrong_url.com')))
我在这里发现:

变更日志

版本说明

5.3.0此功能现在在Windows平台上可用

5.2.4增加了TXT类型

增加了5.0.0 AAAA型


这意味着您无法在windows上的php<5.3下调用此函数,谢谢@aynber的回答。这对我帮助很大。但我认为这对我来说并不完整。我已经修改了一点你的答案来检查电子邮件域是否有效。实际上,它不适用于.co、.co.in、.in域。所以,我把你的答案扩大一点:)


@aynber,+1表示答案:)。

我测试了你的代码,它似乎对我很好。(运行PHP5.3.3)。可能是PHP之外的原因造成的?@Chief17是的,你是对的。我在另一个系统(运行5.3.6)上测试了它,它工作正常。关于如何调试导致当前系统无法正常工作的原因的任何提示?在命令行,尝试
ping
ing/
nslookup
ing域名,看看你得到了什么?我想他的意思是
if(checkdnsrr($url),“A”)
。我看不出有任何理由可以让脚本正常工作。没有冒犯@aurel:)@是的:)这就是他想要的吗wanted@aurelk,但我还是看不出它有什么作用:P@RepWhoringPeeHaa检查url是否已注册。所以,如果你使用google.com,它会说是真的。作为一个诚实的人,我从来没有用过它,我只是看到他的代码缺少brakets@aurel我的意思是说额外的版本是5.3.5
$email = trim($_GET['email']);

// take a given email address and split it into the username and domain.
list($userName, $mailDomain) = split("@", $email);
$tld = explode('.', $mailDomain,2)[1];//for php>=5.4.0
if(checkdnsrr($mailDomain,'A') && !in_array(gethostbyname($mailDomain),gethostbynamel('this_is_a_wrong_url_xx_xx_xx.' . $tld))) {  
echo "Domain exists.";  
} else { 
echo "Domain not exists.";  
}