Free, tested & ready to use examples!
Web - convert files and webpages to any format!

PHP whois client function

This article contains PHP implementation of whois client (as a function ae_whois), which may be used to request domain information from specified whois servers
  • PHP 4.0 or higher
  • PHP 5 or higher
  • Whois protocol (defined by RFC 3912) is probably one of the simplest internet protocols.

    In fact, whois client should open TCP connection to port 43, send query, send CR-LF ("\r\n" constant) and then receive response. Here is the source code:

    source code: php
    function ae_whois($query$server)

    define('AE_WHOIS_TIMEOUT'15); // connection timeout
    global $ae_whois_errno$ae_whois_errstr;

    // connecting 
    $f fsockopen($server43$ae_whois_errno$ae_whois_errstrAE_WHOIS_TIMEOUT);
        if (!
    false// connection failed 

        // sending query    

    // receving response 
    $response '';
        while (!
    $response .= fgets($f1024);

    // closing connection 


    As you can see, function takes two arguments: whois query and whois server. Function returns server response (if everything was fine), or 'false' constant(that means connection failed). fsockopen error code and error string are written to global variables $ae_whois_errno and $ae_whois_errstr.

    You can also change connection timeout by modifying AE_WHOIS_TIMEOUT constant.

    Usage example: getting information about domain ''

    source code: php

    // copy-paste function ae_whois(see above) here 

    echo ae_whois('''');
    ?> is a whois server for .com domains (as of september 2007)


  • Mac OS X 10.4.10 :: PHP 5.2.4
  • Windows 2003 server :: PHP 4.4.5

    © AnyExample 2010-2013
    License | Privacy | Contact