Home >Backend Development >PHP Tutorial >Detailed explanation of the usage of PHP function checkdnsrr (Windows platform usage), detailed explanation of checkdnsrr_PHP tutorial
This article describes the usage of PHP function checkdnsrr with examples. Share it with everyone for your reference, the details are as follows:
This is what it says on php.net:
(PHP 4, PHP 5)
checkdnsrr — Check DNS records corresponding to a given Internet host name or IP address
Translation: checkdnsrr -- Check whether a given host name (domain name) or IP address has a DNS record, which is actually to check whether it exists.
Note: This function is now available on Windows platforms.
Note: This function is not supported on Windows platform
I tried it, and sure enough, it said there is no such function.
The following is a hack method, so that when we develop on Windows, we can also see the effect!
if(!function_exists('checkdnsrr')){ function checkdnsrr($host, $type=''){ if(!empty($host)){ $type = (empty($type)) ? 'MX' : $type; exec('nslookup -type='.$type.' '.escapeshellcmd($host), $result); $it = new ArrayIterator($result); foreach(new RegexIterator($it, '~^'.$host.'~', RegexIterator::GET_MATCH) as $result){ if($result){ return true; } } } return false; } }
Next let me introduce the parameters:
bool checkdnsrr ( string $host [, string $type = "MX" ] )
We won’t talk about the first parameter, it is the domain name or ip
The second parameter is the analysis type, respectively:
A (Address) record is the IP address record corresponding to the specified host name (or domain name).
MX record is the specified mail exchange record (default)
The NS record is a record that specifies the domain name server and specifies which DNS should resolve the domain name.
SOA records are generally used in secondary DNS servers to specify who is the primary server.
PTR record Reverse resolution record pointing from ip to domain name
CNAME record Alias record
The AAAA record is a record pointing to IPv6
A6 record Same as above
SRV record It is a type of resource record supported in the DNS server database. It is generally used when setting up Microsoft's Active Directory.
TXT record Text information
ANY record Any record, all data types
This function is often used by us to detect whether the email actually exists!
Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "php-oriented "Introduction Tutorial on Object Programming", "Summary of PHP String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone in PHP programming.