<?php

/*
    Copyright 2009 Michael Sumner
    Email: msumner@dnmedia.com
    Web: http://www.DNMedia.com
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/ 

if(!isset($_POST['Submit']))
{
    echo 
'<form method="POST" action="' $_SERVER['PHP_SELF'] . '">'
            
'<textarea name="domains" rows="30" cols="30"></textarea><br />'
            
'<input type="submit" name="Submit" value="Submit">'
            
'</form>';
}
else
{
    
$domains explode("\n"str_replace(array("\r\n""\r"), "\n"$_POST['domains']));
    
    foreach(
$domains as $domain)
    {
        if(
is_avail($domain))
        {
            
$pieces explode("."$domain1);
            echo 
$domain " is available.  Buy at <a href=\"http://affiliates.moniker.com/pub/Affiliates?affiliate_id=2176&landingpage=domaincheck&domain=$domain\" target=\"_blank\">Moniker</a> or "
                            
"<a href=\"http://www.godaddy.com/gdshop/registrar/search.asp?isc=cjchst002&domainToCheck=" $pieces[0] . "&tld=" $pieces[1] . "&checkAvail=1\" target=\"_blank\">Godaddy</a>.";
        }
    }
}

function 
is_avail($domain)
{    
    
$pieces explode("."$domain);
    
$server = (count($pieces) == 2) ? $pieces[1] : $pieces[1] . "." $pieces[2];
    
$server .= ".whois-servers.net";
    
$fp fsockopen($server43$errno$errstr10);
    
$result "";
    if(
$fp === FALSE){ return FALSE; }
    
fputs($fp$domain "\r\n");    
    while(!
feof($fp)){ $result .= fgets($fp128); }
    
fclose($fp);
    
    return ((
stristr($result'no match for') !== FALSE) || (strtolower($result) == "notfound\n")) ? TRUE FALSE;
}

?>