I'm trying get a list of CNAME records using PHP.
This method used to work when I was hosting the code on my old Windows 7 machine, but I moved it to an Ubuntu machine (similar AMP stack setup), and it no longer returned CNAME records for the $url
. I uploaded the code to a Windows server and still yet, no CNAME records.
$records['cname'] = dns_get_record($url, DNS_CNAME);
Not that I'm claiming the OS has much to do with anything, maybe I had something set up a certain way on my old machine that allowed this to work. It currently returns a simple empty array, where as it used to return a list of CNAME records that matched up with what was in my DNS management service. I've read the article here:
Why wouldn't dns_get_record show CNAMEs when I KNOW they exist?
and ended up trying to implement the functionality with Pear's NetDns2 Library, with the following code. And still, the answer
array of the response is empty. Not sure if the problem is the same from get_dns_record to NetDNS2 or if I'm doing something wrong in both cases, but the sites tested surely have CNAME records, including google.com
and yahoo.com
.
//using Google Name Server
$rslvr = new Net_DNS2_Resolver(array('nameservers' => array('8.8.8.8')));
$records['cname'] = $rslvr->query($url, 'CNAME');
Any help is appreciated, the end goal is to be able to obtain a list of CNAME records like I was on my old machine.