The checkdnsrr() function is an inbuilt function in PHP which is used to check the DNS records corresponding to the hostname or IP address. This function can be used to verify whether a domain name exists or not.
Syntax:
bool checkdnsrr( string $host, string $type )
Parameters: This function accepts two parameters as mentioned above and described below:
- $host: It is required parameter. It specifies the host name or IP address which to be checked.
- $type: It is optional parameter. It specifies the type of DNS record to be checked. Its possible values are: A, AAAA, A6, ANY, CNAME, MX (default), NAPTR, NS, PTR, SOA, SRV, TXT.
Return Value: This function returns TRUE if records found, otherwise returns FALSE.
Note:
- This function is available for PHP 4.0.0 and newer version.
- On Windows platforms this function is available from PHP 5.3.0.
Below programs illustrate the checkdnsrr() function in PHP:
Program 1:
<?php $domain = "geeksforgeks.org"; if(checkdnsrr($domain, "MX")) { echo "Record exists."; } else { echo "Record not found or error occured."; } ?> |
Output:
Record exists.
Program 2:
<?php $domain = "geeksforgeks.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
Reference: https://www.php.net/manual/en/function.checkdnsrr.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- D3.js | d3.sum() function
- p5.js | mag() Function
- D3.js | d3.max() function
- PHP | next() Function
- p5.js | nfs() Function
- p5.js | nf() Function
- p5.js | nfc() function
- p5.js | nfp() Function
- PHP | Ds\Set add() Function
- PHP | each() Function
- p5.js | box() Function
- D3.js | d3.mean() function
- PHP | pow( ) Function
- D3.js zip() Function
- p5.js | pan() Function
- PHP | min( ) Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

