PHP Checkdnsrr () Function

PHP

Syntax:
bool checkdnsrr (string $host, string $type )
Parameters:This function takes two parameters as above and described below:
  • $host:Required parameter. It specifies the hostname or IP address to be verified.
  • $type:This is an optional parameter. Specifies the type of DNS record to check. Possible values: A, AAAA, A6, ANY, CNAME, MX (default), NAPTR, NS, PTR, SOA, SRV, TXT.
Returned value: this function returns TRUE if records are found, otherwise it returns FALSE.Notes :
  • This function is available for PHP 4.0. 0 and newer.
  • On Windows platforms, this function is available from PHP 5.3.0.
The following programs illustrate the checkdnsrr() function in PHP:Program 1: $domain = "engineerforgeks.org" ; if ( checkdnsrr ( $domain , "MX" )) { echo "Record exists." ; } else { echo "Record not found or error occured." ; }
?>
Output:
Record exists.
Program 2: $domain = "engineerforgeks.org" ; $arr = array ( "A" , "MX" , "NS" , "SOA" , "PTR" , "CNAME" , "AAAA" , "A6" , "SRV" , "NAPTR" , "TXT" , "ANY"); foreach ( $arr as $element ) { echo $element . ":" ; if ( checkdnsrr ( $domain , $element )) { echo "found < br >" ; } else { echo "not found < br >" ; } }  
?>
Output:
A: found MX: found NS: found SOA: found PTR: found CNAME: found AAAA: found A6: found SRV: found NAPTR: found TXT: found ANY: found
Link: https://www.php.net/manual/en/ function.checkdnsrr.php