English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP tutorial

Advanced PHP tutorial

PHP & MySQL

PHP reference manual

PHP checkdnsrr() function usage and example

PHP HTTP  reference manual

The checkdnsrr() function performs DNS communication checks for the specified host (domain) or IP address

Syntax

bool checkdnsrr ( string $host [, string $type = "MX" ] )

Definition and usage

It checks the DNS records of the corresponding host or IP address.

Parameters

ParametersDescription
hostPossible IP address or hostname of the host
typeThe type can be any of the following: A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT or ANY.

Return value

 If the record can be found, it returns TRUE; if the DNS record cannot be found or an error occurs, it returns FALSE.

Update log

PHP 5.3.0  -  This function can also be used on the Windows platform.
PHP 5.2.4  -  Added TXT record type.
PHP 5.0.0  -  Added AAAA record type.

Online example

Try the following example

<?php
function validate_email($email) {
   $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
   if (eregi($exp, $email)) {
      if (checkdnsrr(array_pop(explode("@", $email)), "MX")) {
        return true;
      } else {
        return false;
      }
   } else {
      return false;
   }    
}
?>

The following code will check if the password is valid

PHP HTTP  reference manual