THE WORLD'S LARGEST WEB DEVELOPER SITE

PHP Tutorial

PHP HOME PHP Intro PHP Install PHP Syntax PHP Comments PHP Variables PHP Echo / Print PHP Data Types PHP Strings PHP Numbers PHP Constants PHP Operators PHP If...Else...Elseif PHP Switch PHP While Loops PHP For Loops PHP Functions PHP Arrays PHP Superglobals

PHP Forms

PHP Form Handling PHP Form Validation PHP Form Required PHP Form URL/E-mail PHP Form Complete

PHP Advanced

PHP Date and Time PHP Include PHP File Handling PHP File Open/Read PHP File Create/Write PHP File Upload PHP Cookies PHP Sessions PHP Filters PHP Filters Advanced PHP JSON

PHP OOP

PHP What is OOP PHP Classes/Objects PHP Constructor PHP Destructor PHP Access Modifiers PHP Inheritance PHP Constants PHP Abstract Classes PHP Traits PHP Static Methods PHP Static Properties

MySQL Database

MySQL Database MySQL Connect MySQL Create DB MySQL Create Table MySQL Insert Data MySQL Get Last ID MySQL Insert Multiple MySQL Prepared MySQL Select Data MySQL Delete Data MySQL Update Data MySQL Limit Data

PHP XML

PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM

PHP - AJAX

AJAX Intro AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX Poll

PHP Examples

PHP Examples PHP Quiz PHP Exercises PHP Certificate

PHP Reference

PHP Overview PHP Array PHP Calendar PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP JSON PHP Libxml PHP Mail PHP Math PHP Misc PHP MySQLi PHP Network PHP SimpleXML PHP Stream PHP String PHP XML Parser PHP Zip PHP Timezones

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