mikepultz / netdns2

Native PHP DNS Resolver and Updater
https://netdns2.com/
Other
119 stars 64 forks source link

How to get CNAME of a domain #54

Closed ProgrammerNomad closed 8 years ago

ProgrammerNomad commented 8 years ago

Hello,

I am using netdns2 in all other records working fine but i dont know who to get CNAME records of domain.

Please provide me any example. it will be very help full for my project.

mikepultz commented 8 years ago

Hello,

Getting a CNAME record is just like getting any other record:


$r = new Net_DNS2_Resolver(array('nameservers' => array('8.8.8.8')));
try {

    $result = $r->query('ftp.mrhost.ca', 'CNAME');    

    foreach($result->answer as $rr)
    {
        printf("ftp.mrhost.ca -> %s\n", $rr->cname);
    }

} catch(Net_DNS2_Exception $e) {        

    echo "::query() failed: ", $e->getMessage(), "\n";    
}

This would output:

ftp.mrhost.ca -> ftp.rr.mrhost.ca

Mike