PHP dns_check_record() Function
The PHP dns_check_record() function searches DNS for records of specified type corresponding to the specified hostname. The function returns true if records of specified type are found, otherwise returns false.
This function is an alias of checkdnsrr() function.
Syntax
dns_check_record(hostname, type)
Parameters
hostname |
Required. Specify an IP address or host name to check. |
type |
Optional. Specify the record type to check. It can be any one of the following:
|
Return Value
Returns true if any records are found; returns false if no records were found or if an error occurred.
Example:
The example below shows the usage of dns_check_record() function.
<?php $domain="alphacodingskills.com"; //checking for 'MX' records if(dns_check_record($domain, "MX")){ echo "Records exists."; } else { echo "Records do not exist or an error occurred."; } ?>
The output of the above code will be similar to:
Records exists.
Example:
Consider one more example where other record types are checked.
<?php $domain="alphacodingskills.com"; $types = ["A", "MX", "NS", "SOA", "PTR", "CNAME", "AAAA", "A6", "SRV", "NAPTR", "TXT", "ANY"]; //checking for record types foreach($types as $i){ if(dns_check_record($domain, $i)){ echo "$i : found \n"; } else { echo "$i : Not found \n"; } } ?>
The output of the above code will be similar to:
A : found MX : found NS : found SOA : found PTR : Not found CNAME : Not found AAAA : Not found A6 : Not found SRV : Not found NAPTR : Not found TXT : found ANY : found
❮ PHP Network Reference