Monday, September 17, 2012

checkdnsrr() PHP always return true or false, alternative with Windows

Have you had problem with the PHP function checkdnsrr() is always returning false?
Then you should first check if your php-version is >= 5.3.0 otherwise it wont function in Windows environment.

Have you had problems with checkdnsrr() is always returning true?
Then there may be other problems with windows not able to do the DNS-record check properly.

An alternative to checkdnsrr() with Windows built in function, "nslookup" and by wiriting this much self-explaining php-code:

    if(!empty($host)) {
        $recType="ns";
        exec("nslookup -type=$recType $host",$output);
        foreach($output as $line) {
            if(preg_match("/^$host/", $line)) {
                return true;
            }
        }
        return false;
    }
    return false;

Good luck!

No comments:

Post a Comment