#native_company# #native_desc#
#native_cta#

A Quick Little ‘Whois’ Program.

By David Weber
on August 29, 2000

<?php
//--------------------------------------------
----------------------------------
// Copyright 2000 Domain-Zone.com
// 
// This program may be freely distributed, so long as this copyright stays
// intact.
//-------------------------------------------
-----------------------------------

//******************************************************************************
// Invoke this php script as a URL:
//
// http://yourdomainpath/whois.phtml?Domain=domain-zone.com
//
//                 OR
//
// Invoke this php script from a form:
//
// <form method="post" action="http://yourdomainpath/whois.phtml>
// <input type="text" name="Domain">
// <input type="submit" name="submit" value="submit">
// </form> 
//
//******************************************************************************

//-------------------------------------------------
-----------------------------// Function:  get_whois()
//
// Description:  This PHP function retrieves the domain registration information
//               from the specified whois server for the specified domain.  
//
//               If the specified server is the registrar for the specified
//               domain, the function returns the registration information in 
//               the $output variable and returns a "0" as the function's 
//               return value.
// 
//               If the specified server is not the registrar for the specified 
//               domain, the function returns the registrar's server name in 
//               the $output variable and returns a "1" as the function's 
//               return value.
//
// Arguments:    $server - this is the name of the whois server 
//                         (ie) rs.internic.net
//               $domain - the domain whose registration we are searching for 
//                         (ie) domain-zone.com
//               $output - domain registration info if return value = 0
//                       - server name for registrar that has the registration 
//                         info if return value = 1
//
// Return Value: 0 = specified server is not the registrar for the specified 
//                   domain
//               1 = specified server is the registrar for the specified domain
//------------------------------------------------------------------------------
function get_whois($server,$domain,&$output)
{
    $whois = fsockopen($server, 43);
    fputs($whois, "$domainrn");
    $result = "";
    while(!feof($whois))
    {
        $str = fgets($whois, 1024);
        $result .= $str;
        if (strstr($str, "Whois Server:"))
        {
            $new_server = split(": ", $str);
            $output = chop("$new_server[1]");  
            fclose($whois);
            return(1);   
        }
    }
    $output = $result; 
    fclose($whois);
    return(0);  
}

$output = "";

// look up a domain name at rs.internic.net
$redirect = get_whois("rs.internic.net", $Domain, $output);

// if rs.internic.net doesn't have the information, $output will give us the 
// server that does, so use it to get the registration info
while ($redirect)
{
    $whois_server = $output;
    $redirect = get_whois($whois_server, $Domain, $output);
}

// ouput the domain registration information
echo $output;        

?>