drzrzzkh462254 2014-10-23 18:51
浏览 40
已采纳

通过get_dns_record循环

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!

  • 写回答

1条回答 默认 最新

  • dongyi2425 2014-11-03 17:14
    关注

    Well, the comments were correct - My code was actually working properly. The reason I was not getting the same results was the way I was exploding on the line breaks from the textarea.

    In order to correctly get the values seperated by line breaks in the textarea, I updated this line:

    $domain = explode( "
    ", $domain );
    

    to

    $domain = explode( "
    ", $domain );
    

    Amazing how something so simple can drive one so crazy!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改