Detailed explanation of the usage of PHP function checkdnsrr (Windows platform usage)_php skills

WBOY
Release: 2016-05-16 19:56:19
Original
1189 people have browsed it

The example in this article describes the usage of PHP function checkdnsrr. 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;
  }
}

Copy after login

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 on this site: "Summary of PHP operating office document skills (including word, excel, access, ppt)", "php date Time usage summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation Introductory tutorial " and " Summary of common PHP database operation skills "

I hope this article will be helpful to everyone in PHP programming.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!