Hello all

What would cause dns_get_record to work with some domains but not with others? I am using a 'DNS_ALL' lookup.

Thanks for any info you can provide

    For the domains that it "doesn't work" with, what happens instead? Do you have error_reporting set to E_ALL and either display_errors or log_errors set to On? If so, are you getting any error/warning/etc. messages?

    EDIT: Also, can you show us the code you're using to retrieve and parse the DNS information?

      bradgrafelman;10954978 wrote:

      For the domains that it "doesn't work" with, what happens instead? Do you have error_reporting set to E_ALL and either display_errors or log_errors set to On? If so, are you getting any error/warning/etc. messages?

      EDIT: Also, can you show us the code you're using to retrieve and parse the DNS information?

      For domains that it doesnt work on, it just displays a blank page. I do not have any sort of error reporting setup.

      Sure, here is the code I am using

      <?php
      
      $domain = $_POST["Domain"];
      
      $dns = dns_get_record( $domain, DNS_ALL );
      foreach( $dns as $d ) {
          // Only print A and MX records
          if( $d['type'] != "A" and $d['type'] != "MX" )
              continue;
          // First print all fields
          echo "For " . $d['host'] . ": <br />\n";
      //    foreach( $d as $key => $value ) {
      //        if( $key != "host" )    // Don't print host twice
      //            echo " {$key}: <b>\n {$value}</b>\n <br />\n";
      //     }
          // Print type specific fields
          switch( $d['type'] ) {
              case 'A':
                  // Display annoying message
                  echo "<b>\n" . $d['ip'] . "</b>\n is the Primary A Record for this domain. <br /><br />\n";
                  break;
              case 'MX':
                  // Resolve IP address of the mail server
                  $mx = dns_get_record( $d['target'], DNS_A );
                  foreach( $mx as $server ) {
                      echo "The MX record for " . $d['host'] . " points to the server <b>\n" . $d['target'] . "</b>\n whose IP address is <b>\n" . $server['ip'] . "</b>. It has a priority of <b>\n" . $d['pri'] . "</b>\n. <br /><br />\n";
                  }
      		if ( $d['target'] == $domain ) {
      			echo "<i>It looks like the domain is using itself as an MX Record.  You will need to create additional records.</i><br /><br />\n";
      				} else {
      			echo "<i>This MX Record looks fine.</i><br /><br />\n";
      			}
                  break;
          }
      }
      
      ?>
      
        Batfan wrote:

        I do not have any sort of error reporting setup.

        Erm.. so you're saying that you know errors are occurring, but don't know why... and that you're ignoring any possible messages from PHP that might explain what's going wrong? Is it just me, or does that seem wrong to you as well? 🙂

        First thing you should do on any production site is setup at least the basic PHP error logging mechanism so you can examine errors on your site (if any).

        Without any error messages, I'm not sure what to suggest... other than to enable error logging.

          bradgrafelman;10954981 wrote:

          Erm.. so you're saying that you know errors are occurring, but don't know why... and that you're ignoring any possible messages from PHP that might explain what's going wrong? Is it just me, or does that seem wrong to you as well? 🙂

          First thing you should do on any production site is setup at least the basic PHP error logging mechanism so you can examine errors on your site (if any).

          Without any error messages, I'm not sure what to suggest... other than to enable error logging.

          I never said "errors" Brad 🙂 I said it wasn't working

          Also, being that I posted in the "newbie" section, I think it may be a good idea to assume that I know (almost) nothing about PHP 😉

          If you feel that we are unable to diagnose this issue without error logging, please throw some of your infinite wisdom this way and tell me how to set that up

            Batfan;10954984 wrote:

            I never said "errors" Brad

            You didn't say it, but you certainly implied it. What else do you call events that make a PHP script not work as expected... successes? :p

            If you know a specific domain that's always causing your script to fail, you could simply use [man]ini_set/man to enable display_errors temporarily to see if PHP spits out anything useful. Otherwise, you could use the same function to enable/configure the [man]log_errors[/man] and [man]error_log[/man] directives to log errors occurring in this script to an error log. Might also want to use the error_reporting() function (manual link: [man]function.error-reporting[/man]) to set the error_reporting level to E_ALL (that's a PHP constant, not a string - don't surround it with quotes; see the manual page if in doubt).

              You may also want to check out what version of PHP your using on each domain (if they are on different servers). If you don't know how to do that just make a test.php file or something and just print out the phpinfo() or phpversion(). dns_get_record is brand new in 5.3.0 so if your rocking any older versions that's why its not working.

                zypher11;10954992 wrote:

                You may also want to check out what version of PHP your using on each domain (if they are on different servers). If you don't know how to do that just make a test.php file or something and just print out the phpinfo() or phpversion(). dns_get_record is brand new in 5.3.0 so if your rocking any older versions that's why its not working.

                I believe the OP meant by passing different domains to the script... it's not being hosted on separate domains.

                  Ah ok i misread that.

                  Excerpt from php.net

                  Using DNS_ALL fails on some domains where DNS_ANY works. I noticed the function getting stuck on the DNS_PTR record, which caused it to return FALSE with this error:
                  PHP Warning: dns_get_record(): res_nsend() failed in ....

                  This gets all records except DNS_PTR:
                  <?php
                  $dnsr = dns_get_record('php.net', DNS_ALL - DNS_PTR);
                  print_r($dnsr);
                  ?>

                  If that's the error you receive when you turn on error reporting try DNS_ALL - DNS_PTR or DNS_ANY if DNS_ALL fails to return an array or throws an error.

                    bradgrafelman;10954987 wrote:

                    You didn't say it, but you certainly implied it. What else do you call events that make a PHP script not work as expected... successes? :p

                    If you know a specific domain that's always causing your script to fail, you could simply use [man]ini_set/man to enable display_errors temporarily to see if PHP spits out anything useful. Otherwise, you could use the same function to enable/configure the [man]log_errors[/man] and [man]error_log[/man] directives to log errors occurring in this script to an error log. Might also want to use the error_reporting() function (manual link: [man]function.error-reporting[/man]) to set the error_reporting level to E_ALL (that's a PHP constant, not a string - don't surround it with quotes; see the manual page if in doubt).

                    Thanks for the feedback. Heres what it produced:

                    Warning: dns_get_record() [function.dns-get-record]: res_nsend() failed in /home/content/d/o/m/domain/html/DNS/full.php on line 5

                    Warning: Invalid argument supplied for foreach() in /home/content/d/o/m/domain/html/DNS/full.php on line 6

                      Sounds like you are indeed facing the same error that zypher11 found referenced in a user-contributed note here.

                      Then again, I note in your code above that you only care about A and MX records... so why, then, are you performing a DNS_ALL type query in the first place?

                        bradgrafelman;10955021 wrote:

                        Sounds like you are indeed facing the same error that zypher11 found referenced in a user-contributed note here.

                        Then again, I note in your code above that you only care about A and MX records... so why, then, are you performing a DNS_ALL type query in the first place?

                        Alrighty, I updated it to DNS_ANY and now its not generating an error. I just get a blank page again.

                        I'm using a full DNS lookup because of the setup I am looking to create.
                        1. I need to grab different properties of multiple records and call on them on different sections of my page.

                        2. I need to pull the IP addresses of the MX Records (their 'targets' specifically).

                        Again, if you are aware of a better setup. Kindly fill me in on it 🙂

                          If you do not have error logging turned on by default (php.ini), but rather use run time functions to set this up, and you have syntax errors in your script then error reporting will not work, since the script is first parsed and then only executed if parsing went ok.
                          As such, I'm guessing you managed to sneak in an error when changing your code.

                          The documentation states that DNS_ANY is not as reliable (across platforms) as DNS_ALL. You'd have to verify that it does indeed do the trick for you. You could also perform two calls to dns_get_record, once with DNS_A and once with DNS_MX.

                          Since this function returns either an array on success, or false on failure, you should test for success.

                          $dns = dns_get_record( $domain, DNS_ALL );
                          // ok, proceed with foreach loop
                          if ($dns) {
                          
                          }
                          // dns_get_record returned false for some reason. Perhaps log $domain?
                          else {
                          
                          }
                          
                            johnafm wrote:

                            You could also perform two calls to dns_get_record, once with DNS_A and once with DNS_MX.

                            Or perform one call with "DNS_A + DNS_MX". 😉

                              bradgrafelman;10955098 wrote:

                              Or perform one call with "DNS_A + DNS_MX". 😉

                              That would be okay except, as I stated, I need to get the A Record associated with the MX 'target' as well 😛

                                Write a Reply...