PHP function checkdnsrr () does not produce expected results

I tested the checkdnsrr () function in PHP to check if the given hostname is valid or not.

The following is the PHP code:

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

But it returns true even for invalid URLs.

What am I doing wrong? I am using PHP 5.3.5

EDIT: This code works fine on Linux machines with the same version of PHP. This gives an invalid result only on a Windows machine.

+3
source share
4 answers

- . TimeWarner/RoadRunner - . , , 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')))
+6

@ynber . . , . , . , .co,.co.in,.in. , :)

$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.";  
}

@aynber, +1 :).

+1

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

$url

0

:

http://php.net/manual/en/function.checkdnsrr.php

5.3.0 Windows.

5.2.4 TXT .

5.0.0 AAAA.

This means that you cannot call this function under php <5.3 on windows

-2
source

All Articles