Heres a quick rundown of whats going on and where the problem is... $_POST['domain_list'] is an array of domains the user can enter seperated by line breaks (hence the explode on ) The first var dump gives me:
array(3) { [0]=> string(11) "google.com " [1]=> string(17) "websolutions.com " [2]=> string(12) "facebook.com" }
Which is what I want - The 3 hostnames I entered in the textarea.
So then the first foreach is looping through that array and assigning each hostname to the dns_get_record function.
Which leads to the problem I'm having - The 2 loops inside that pull the IP and Nameservers, only pull the last domain. So those 2 var dumps look something like:
array(5) { ["host"]=> string(12) "facebook.com" ["type"]=> string(1) "A" ["ip"]=> string(13) "173.252.120.6" ["class"]=> string(2) "IN" ["ttl"]=> int(900) } Hostname: facebook.com IP: 173.252.120.6
array(5) { ["host"]=> string(12) "facebook.com" ["type"]=> string(2) "NS" ["target"]=> string(17) "a.ns.facebook.com" ["class"]=> string(2) "IN" ["ttl"]=> int(172528) } Hostname: facebook.com NS: a.ns.facebook.com
array(5) { ["host"]=> string(12) "facebook.com" ["type"]=> string(2) "NS" ["target"]=> string(17) "b.ns.facebook.com" ["class"]=> string(2) "IN" ["ttl"]=> int(172528) } Hostname: facebook.com NS: b.ns.facebook.com
For some reason, the main loop isn't working like I expect it to, I was expecting it to loop through the entire $domain array (which you can see in the first var_dump, it DOES have all 3 domains in the array)
if ( isset( $_POST['domain_list'] ) ) {
$domain = $_POST['domain_list'];
$domain = explode( "
", $domain );
var_dump( $domain );
foreach ( $domain as $entry ) {
$a_record = dns_get_record( $entry, DNS_A );
$nameservers = dns_get_record( $entry, DNS_NS );
foreach($a_record as $arr1) {
var_dump($arr1);
echo 'Hostname: '.$arr1['host'].' IP: '.$arr1['ip'] . '<br>';
}
foreach($nameservers as $arr2) {
var_dump($arr2);
echo 'Hostname: '.$arr2['host'].' NS: '.$arr2['target'] . '<br>';
}
}
} else {
echo "failed";
}
Thanks in advance!