downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.dns-get-record.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.network.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.dns-get-record.php',
   
1 => 'dns_get_record',
  ),
 
'up' =>
  array (
   
0 => 'ref.network.php',
   
1 => 'Network Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.dns-get-mx.php',
   
1 => 'dns_get_mx',
  ),
 
'next' =>
  array (
   
0 => 'function.fsockopen.php',
   
1 => 'fsockopen',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.dns-get-record" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">dns_get_record</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">dns_get_record</span> &mdash; <span class="dc-title">Fetch DNS Resource Records associated with a hostname</span></p>

 </div>
 
 <a name="function.dns-get-record.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><b>dns_get_record</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$hostname</tt></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$type</tt><span class="initializer"> = DNS_ANY</span></span>
   [, <span class="methodparam"><span class="type">array</span> <tt class="parameter reference">&amp;$authns</tt></span>
   [, <span class="methodparam"><span class="type">array</span> <tt class="parameter reference">&amp;$addtl</tt></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   Fetch DNS Resource Records associated with the given
   <i><tt class="parameter">hostname</tt></i>
.
  </p>
 </div>


 <a name="function.dns-get-record.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">hostname</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       <i><tt class="parameter">hostname</tt></i>
 should be a valid DNS hostname such
       as &quot;<i>www.example.com</i>&quot;. Reverse lookups can be generated
       using <i>in-addr.arpa</i> notation, but
       <a href="function.gethostbyaddr.php" class="function">gethostbyaddr()</a> is more suitable for
       the majority of reverse lookups.
      </p>
      <blockquote><p><b class="note">Note</b>:
      
        Per DNS standards, email addresses are given in <i>user.host</i> format (for
        example: <i>hostmaster.example.com</i> as opposed to <i>hostmaster@example.com</i>),
        be sure to check this value and modify if necessary before using it
        with a functions such as <a href="function.mail.php" class="function">mail()</a>.
       <br />
      </p></blockquote>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">type</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       By default, <b>dns_get_record()</b> will search for any
       resource records associated with <i><tt class="parameter">hostname</tt></i>
.
       To limit the query, specify the optional <i><tt class="parameter">type</tt></i>

       parameter. May be any one of the following:
       <b><tt class="constant">DNS_A</tt></b>, <b><tt class="constant">DNS_CNAME</tt></b>,
       <b><tt class="constant">DNS_HINFO</tt></b>, <b><tt class="constant">DNS_MX</tt></b>,
       <b><tt class="constant">DNS_NS</tt></b>, <b><tt class="constant">DNS_PTR</tt></b>,
       <b><tt class="constant">DNS_SOA</tt></b>, <b><tt class="constant">DNS_TXT</tt></b>,
       <b><tt class="constant">DNS_AAAA</tt></b>, <b><tt class="constant">DNS_SRV</tt></b>,
       <b><tt class="constant">DNS_NAPTR</tt></b>, <b><tt class="constant">DNS_A6</tt></b>,
       <b><tt class="constant">DNS_ALL</tt></b> or <b><tt class="constant">DNS_ANY</tt></b>.
       The default is <em class="emphasis">DNS_ANY</em>.
      </p>
      <blockquote><p><b class="note">Note</b>:
      
        Because of eccentricities in the performance of libresolv
        between platforms, <b><tt class="constant">DNS_ANY</tt></b> will not
        always return every record, the slower <b><tt class="constant">DNS_ALL</tt></b>
        will collect all records more reliably.
       <br />
      </p></blockquote>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">authns</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Passed by reference and, if given, will be populated with Resource
       Records for the <em class="emphasis">Authoritative Name Servers</em>.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">addtl</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Passed by reference and, if given, will be populated with any
       <em class="emphasis">Additional Records</em>.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.dns-get-record.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   This function returns an array of associative arrays.  Each associative array contains
   <em class="emphasis">at minimum</em> the following keys:
   </p><table class="doctable table">
    <caption><b>Basic DNS attributes</b></caption>
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Attribute</th>
       <th>Meaning</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">host</td>
       <td align="left">
        The record in the DNS namespace to which the rest of the associated data refers.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">class</td>
       <td align="left">
        <b>dns_get_record()</b> only returns Internet class records and as
        such this parameter will always return <i>IN</i>.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">type</td>
       <td align="left">
        String containing the record type.  Additional attributes will also be contained
        in the resulting array dependant on the value of type. See table below.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left">ttl</td>
       <td align="left">
        <i>&quot;Time To Live&quot;</i> remaining for this record. This will <em class="emphasis">not</em> equal
        the record&#039;s original ttl, but will rather equal the original ttl minus whatever
        length of time has passed since the authoritative name server was queried.
       </td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
  <p class="para">
   </p><table class="doctable table">
    <caption><b>Other keys in associative arrays dependant on &#039;type&#039;</b></caption>
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Type</th>
       <th>Extra Columns</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left"><i>A</i></td>
       <td align="left">
        <i>ip</i>: An IPv4 addresses in dotted decimal notation.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>MX</i></td>
       <td align="left">
        <i>pri</i>: Priority of mail exchanger.
        Lower numbers indicate greater priority.
        <i>target</i>: FQDN of the mail exchanger.
        See also <a href="function.dns-get-mx.php" class="function">dns_get_mx()</a>.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>CNAME</i></td>
       <td align="left">
        <i>target</i>: FQDN of location in DNS namespace to which
        the record is aliased.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>NS</i></td>
       <td align="left">
        <i>target</i>: FQDN of the name server which is authoritative
        for this hostname.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>PTR</i></td>
       <td align="left">
        <i>target</i>: Location within the DNS namespace to which
        this record points.
       </td>
      </tr>

       <tr valign="middle">
       <td align="left"><i>TXT</i></td>
       <td align="left">
        <i>txt</i>: Arbitrary string data associated with this record.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>HINFO</i></td>
       <td align="left">
        <i>cpu</i>: IANA number designating the CPU of the machine
        referenced by this record.
        <i>os</i>: IANA number designating the Operating System on
        the machine referenced by this record.
        See IANA&#039;s <a href="http://www.iana.org/assignments/operating-system-names" class="link external">&raquo; <i>Operating System
        Names</i></a> for the meaning of these values.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>SOA</i></td>
       <td align="left">
        <i>mname</i>: FQDN of the machine from which the resource
        records originated.
        <i>rname</i>: Email address of the administrative contain
        for this domain.
        <i>serial</i>: Serial # of this revision of the requested
        domain.
        <i>refresh</i>: Refresh interval (seconds) secondary name
        servers should use when updating remote copies of this domain.
        <i>retry</i>: Length of time (seconds) to wait after a
        failed refresh before making a second attempt.
        <i>expire</i>: Maximum length of time (seconds) a secondary
        DNS server should retain remote copies of the zone data without a
        successful refresh before discarding.
        <i>minimum-ttl</i>: Minimum length of time (seconds) a
        client can continue to use a DNS resolution before it should request
        a new resolution from the server.  Can be overridden by individual
        resource records.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>AAAA</i></td>
       <td align="left">
        <i>ipv6</i>: IPv6 address
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>A6</i>(PHP &gt;= 5.1.0)</td>
       <td align="left">
        <i>masklen</i>: Length (in bits) to inherit from the target
        specified by <i><tt class="parameter">chain</tt></i>
.
        <i>ipv6</i>: Address for this specific record to merge with
        <i><tt class="parameter">chain</tt></i>
.
        <i>chain</i>: Parent record to merge with
        <i><tt class="parameter">ipv6</tt></i>
 data.
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>SRV</i></td>
       <td align="left">
        <i>pri</i>: (Priority) lowest priorities should be used first.
        <i>weight</i>: Ranking to weight which of commonly prioritized
        <i><tt class="parameter">targets</tt></i>
 should be chosen at random.
        <i>target</i> and <i>port</i>: hostname and port
        where the requested service can be found.
        For additional information see: <a href="http://www.faqs.org/rfcs/rfc2782" class="link external">&raquo; RFC 2782</a>
       </td>
      </tr>

      <tr valign="middle">
       <td align="left"><i>NAPTR</i></td>
       <td align="left">
        <i>order</i> and <i>pref</i>: Equivalent to
        <i><tt class="parameter">pri</tt></i>
 and <i><tt class="parameter">weight</tt></i>
 above.
        <i>flags</i>, <i>services</i>, <i>regex</i>,
        and <i>replacement</i>: Parameters as defined by
        <a href="http://www.faqs.org/rfcs/rfc2915" class="link external">&raquo; RFC 2915</a>.
       </td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
 </div>


 <a name="function.dns-get-record.changelog"></a><div class="refsect1 changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   </p><table class="doctable informaltable">
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">5.3.0</td>
       <td align="left">
         This function is now available on Windows platforms.
       </td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
 </div>


 <a name="function.dns-get-record.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 Using <b>dns_get_record()</b></b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dns_get_record</span><span style="color: #007700">(</span><span style="color: #DD0000">"php.net"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents para"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; MX
            [pri] =&gt; 5
            [target] =&gt; pair2.php.net
            [class] =&gt; IN
            [ttl] =&gt; 6765
        )

    [1] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; A
            [ip] =&gt; 64.246.30.37
            [class] =&gt; IN
            [ttl] =&gt; 8125
        )

)
</pre></div>
    </div>
   </div><p>
   </p><div class="example">
    <p><b>Example #2 Using <b>dns_get_record()</b> and DNS_ANY</b></p>
    <div class="example-contents para"><p>
     Since it&#039;s very common to want the IP address of a mail server
     once the MX record has been resolved, <b>dns_get_record()</b>
     also returns an array in <i><tt class="parameter">addtl</tt></i>
 which
     contains associate records.  <i><tt class="parameter">authns</tt></i>

     is returned as well containing a list of authoritative name
     servers.
    </p></div>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Request&nbsp;"ANY"&nbsp;record&nbsp;for&nbsp;php.net,<br />&nbsp;&nbsp;&nbsp;and&nbsp;create&nbsp;$authns&nbsp;and&nbsp;$addtl&nbsp;arrays<br />&nbsp;&nbsp;&nbsp;containing&nbsp;list&nbsp;of&nbsp;name&nbsp;servers&nbsp;and<br />&nbsp;&nbsp;&nbsp;any&nbsp;additional&nbsp;records&nbsp;which&nbsp;go&nbsp;with<br />&nbsp;&nbsp;&nbsp;them&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dns_get_record</span><span style="color: #007700">(</span><span style="color: #DD0000">"php.net"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">DNS_ANY</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$authns</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$addtl</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Result&nbsp;=&nbsp;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Auth&nbsp;NS&nbsp;=&nbsp;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$authns</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Additional&nbsp;=&nbsp;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$addtl</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents para"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Result = Array
(
    [0] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; MX
            [pri] =&gt; 5
            [target] =&gt; pair2.php.net
            [class] =&gt; IN
            [ttl] =&gt; 6765
        )

    [1] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; A
            [ip] =&gt; 64.246.30.37
            [class] =&gt; IN
            [ttl] =&gt; 8125
        )

)
Auth NS = Array
(
    [0] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; remote1.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

    [1] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; remote2.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

    [2] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; ns1.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

    [3] =&gt; Array
        (
            [host] =&gt; php.net
            [type] =&gt; NS
            [target] =&gt; ns2.easydns.com
            [class] =&gt; IN
            [ttl] =&gt; 10722
        )

)
Additional = Array
(
    [0] =&gt; Array
        (
            [host] =&gt; pair2.php.net
            [type] =&gt; A
            [ip] =&gt; 216.92.131.5
            [class] =&gt; IN
            [ttl] =&gt; 6766
        )

    [1] =&gt; Array
        (
            [host] =&gt; remote1.easydns.com
            [type] =&gt; A
            [ip] =&gt; 64.39.29.212
            [class] =&gt; IN
            [ttl] =&gt; 100384
        )

    [2] =&gt; Array
        (
            [host] =&gt; remote2.easydns.com
            [type] =&gt; A
            [ip] =&gt; 212.100.224.80
            [class] =&gt; IN
            [ttl] =&gt; 81241
        )

    [3] =&gt; Array
        (
            [host] =&gt; ns1.easydns.com
            [type] =&gt; A
            [ip] =&gt; 216.220.40.243
            [class] =&gt; IN
            [ttl] =&gt; 81241
        )

    [4] =&gt; Array
        (
            [host] =&gt; ns2.easydns.com
            [type] =&gt; A
            [ip] =&gt; 216.220.40.244
            [class] =&gt; IN
            [ttl] =&gt; 81241
        )

)
</pre></div>
    </div>
   </div><p>
  </p>
 </div>


 <a name="function.dns-get-record.notes"></a><div class="refsect1 notes">
  <h3 class="title">Notes</h3>
  <blockquote><p><b class="note">Note</b>:
  
    For compatibility with versions before this function was implemented
    on such platforms as Windows, *BSD and MAC. Try the
    <a href="http://pear.php.net/" class="link external">&raquo; PEAR</a> class
    <a href="http://pear.php.net/package/Net_DNS" class="link external">&raquo; Net_DNS</a>.
   <br />
  </p></blockquote>
 </div>


 <a name="function.dns-get-record.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.dns-get-mx.php" class="function" rel="rdfs-seeAlso">dns_get_mx()</a> - Alias of getmxrr</li>
    <li class="member"><a href="function.dns-check-record.php" class="function" rel="rdfs-seeAlso">dns_check_record()</a> - Alias of checkdnsrr</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites