PHP dns_get_record() Function

❮ PHP Network Reference

Example

Gets the MX resource records associated with "www.w3schools.com":

<?php
print_r(dns_get_record("w3schools.com", DNS_MX));
?>


Definition and Usage

The dns_get_record() function gets the DNS resource records associated with the specified hostname.

Syntax

dns_get_record(hostname, type, authns, addtl, raw)

Parameter Values

Parameter Description
hostname Required. Specifies a hostname (like "www.w3schools.com")
type Optional. Specifies the resource record type to search for. Can be one of the following:
  • DNS_A
  • DNS_CNAME
  • DNS_HINFO
  • DNS_CAA
  • DNS_MX
  • DNS_NS
  • DNS_PTR
  • DNS_SOA
  • DNS_TXT
  • DNS_AAAA
  • DNS_SRV
  • DNS_NAPTR
  • DNS_A6
  • DNS_ALL
  • DNS_ANY (default)
authns Optional. Passed by reference and, if set, it will be populated with Resource Records for the Authoritative Name Servers
addtl Optional. Passed by reference and, if set, it will be populated with any Additional Records
raw Optional. A Boolean value. If set to TRUE, it queries only the requested type instead of looping type-by-type before getting the info stuff. Default is FALSE


Technical Details

Return Value:

An array of associative arrays, FALSE on failure. Each array contains the following keys (at minimum):

  • host - The hostname
  • class - Always return IN (because this function only returns Internet class records)
  • type - The record type
  • ttl - "Time To Live" remaining for this record (original ttl minus the length of time passed since the server was queried)

Other keys in the arrays depends on the type parameter.

PHP Version: 5.0+
PHP Changelog: PHP 7.0.16: Added support for DNS_CAA type.
PHP 5.4: Added the raw parameter.
PHP 5.3: Available on Windows platforms.

❮ PHP Network Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.