PHPresolver - a simple dns resolver library for php SourceForge Logo
project page | download | browse CVS | reference | demonstration

[Japanese]

News

2003/06/11

Hi there. The project is still alive... I'd like to thank anyone who sent me patches and helpful comments! I'm going to release a new version anytime soon. Stay tuned.

2002/08/26

I recently noticed more consistent package Net_DNS by Eric Kilfoil is available in PEAR repository.
If you are looking for functionality such as dynamic DNS update, try that one.

What is PHPresolver?

PHPresolver is a LGPL'ed DNS resolver library written in 100% pure PHP that features object-oriented interface and platform independency.

Sample code: retrieving MX records.
<?php

    require_once( "DNS.php" );

    $mailaddr = "example@example.com";

    list( $dummy, $domain ) = explode( '@', $mailaddr );

    $resolver = new DNSResolver( "ns.example.com" );
    $dnsname = & DNSName::newFromString( $domain );
    $answer = & $resolver->sendQuery(
        new DNSQuery(
            new DNSRecord( $dnsname, DNS_RECORDTYPE_MX )
        )
    );
    if( !$answer || !$answer->rec_answer ) {
        print "DNS resolution failed.";
    } else {
        $i = count( $answer->rec_answer );
        while( --$i >= 0 ) {
            if( $answer->rec_answer[$i]->type == DNS_RECORDTYPE_MX ) {
                $record = & $answer->rec_answer[$i];
                $mxname = $record->specific_fields['exchange'];
                print "mail exchange: ";
                print $mxname->getCanonicalName();
                print "<BR>\n";
            }
        }
    }
?>

Background

PHP(3 or 4) has some DNS resolver functions such as:
But indeed as for the current distribution, neither getmxrr() nor checkdnsrr() is supported on native Win32 (except for custom builds with bindlib_w32 support) or BeOS, because a DNS resolver implementation required for building those PHP functions is lacking in these platforms.
If you've been doing with PHP in Win32 or BeOS environment you might have once wondered why you got getmxrr()-is-not-supported warning and given up coding a kind of e-mail address validity verification.

As you might know, if the future versions of PHP natively support these functions, the library will not be needed any longer...

Requirements

Getting started

Installation

All you have to do is simply put the file (just DNS.php!) on the suitable place.

Testing

If you are using PHP with a HTTP server, try dnstest.php.

NOTE: you have to rewrite * require_once * statement in the beginning of "dnstest.php" to specify the location of the library if necessary.

Resources

RFC1034: DOMAIN NAMES - CONCEPTS AND FACILITIES
RFC1035: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION
RFC1886: DNS Extensions to support IP version 6
RFC2874: DNS Extensions to Support IPv6 Address Aggregation and Renumbering

Discussion over AAAA RR v.s. A6 RR

RFC3363: Representing Internet Protocol version 6 (IPv6) Addresses in the Domain Name System (DNS)
RFC3364: Tradeoffs in Domain Name System (DNS) Support for Internet Protocol version 6 (IPv6)