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

PHP Basic Tutorial

PHP Advanced 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 checks if the password is valid

PHP HTTP Reference Manual