Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP checkdnsrr() function not giving expect results

Tags:

function

php

I was trying out checkdnsrr() function in PHP to test whether a given hostname is valid or not.

Below 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 is returning true even for invalid url's.

What am I doing wrong? I am using PHP 5.3.5

EDIT: This code is working fine on Linux machines with same PHP version. Its giving invalid result only on Windows machine.

like image 954
AnonGeek Avatar asked Jan 01 '26 23:01

AnonGeek


1 Answers

Some ISPs will redirect invalid domains to their own search servers. TimeWarner/RoadRunner is one such ISP. Your code works fine, but you might want to check to make sure they don't resolve to your ISP's search servers. Use gethostbyname first to check an invalid domain, then use that to check against.

if (checkdnsrr($url, 'A') && gethostbyname($url) != '204.232.137.207' && gethostbyname($url) !='66.152.109.110')

Or better is

if(checkdnsrr($url,'A') && !in_array(gethostbyname($url),gethostbynamel('this_is_a_wrong_url.com')))
like image 56
aynber Avatar answered Jan 03 '26 14:01

aynber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!