Jump to content

Checking domain availibility


rvdb86

Recommended Posts

hey I have the following script that is meant to check domain availibility:

<?php
// List of whois servers
$serverList[0]['top']      = 'com';
$serverList[0]['server']   = 'whois.crsnic.net';
$serverList[0]['response'] = 'No match for';
$serverList[0]['check']    = true;

$serverList[1]['top']      = 'net';
$serverList[1]['server']   = 'whois.crsnic.net';
$serverList[1]['response'] = 'No match for';
$serverList[1]['check']    = false;

$serverList[2]['top']      = 'org';
$serverList[2]['server']   = 'whois.publicinterestregistry.net';
$serverList[2]['response'] = 'NOT FOUND';
$serverList[2]['check']    = false;

$serverList[3]['top']      = 'co.il';
$serverList[3]['server']   = 'whois.isoc.org.il';
$serverList[3]['response'] = 'NOT FOUND';
$serverList[3]['check']    = false;



    function checkDomain($domain,$server,$findText){
        // Open a socket connection to the whois server

        $con = fsockopen($server, 43);
        if (!$con) return false;
        
        // Send the requested doman name
        fputs($con, $domain."\r\n");
        
        // Read and store the server response
        $response = ' :';
        while(!feof($con)) {
            $response .= fgets($con,128); 
        }
        
        // Close the connection
        fclose($con);
        
        // Check the response stream whether the domain is available
        if (strpos($response, $findText)){
            return true;
        }
        else {
            return false;   
        }
    }

    function showDomainResult($domain,$server,$findText){
       if (checkDomain($domain,$server,$findText)){
          echo "<tr><td>$domain</td><td>AVAILABLE</td></tr>";
       }
       else echo "<tr><td>$domain</td><td>TAKEN</td></tr>";
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Mini Domain Checker</title>
</head>
<body>
<?php if (!isset($_POST['submitBtn'])) { ?>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain" id="domain">
        Domain name:
        <table>
          <tr><td><input class="text" name="domainname" type="text" size="36"/></td></tr>
          <tr>
            <td>
                <input type="checkbox" name="all" />All
            <?php
            	foreach ($serverList as $value) {
            		if ($value['check'] == true) $checked=" checked ";
            		else $checked = " ";
            		
            		echo '<input type="checkbox" name="top_'.$value['top'].'"'.$checked.'/>.'.$value['top'];
            	}
            ?>
            </td></tr>
            <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Check domain"/></td></tr>
        </table>  
      </form>
<?php    
} else {
    $domainName = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
    if (isset($_POST['all'])) {
      	// As all was selected so set all top level domains to be checked.
       	for ($i = 0; $i < sizeof($serverList); $i++) {
       		$serverList[$i]['check'] = true;
       	}
    }
    else{
       	for ($i = 0; $i < sizeof($serverList); $i++) {
       		$actTop = "top_".$serverList[$i]['top'];
       		$serverList[$i]['check'] = isset($_POST[$actTop]) ? true : false;
       	}
    }

    // Check domains only if the base name is big enough
    if (strlen($domainName)>2){
        echo '<table>';

       	for ($i = 0; $i < sizeof($serverList); $i++) {
		if ($serverList[$i]['check']){
			showDomainResult($domainName.".".$serverList[$i]['top'],$serverList[$i]['server'],$serverList[$i]['response']);
		}
	}
        
	echo '</table>';
    }
}
?>    
</body>   

 

The problem is with .co.il domains. i check that whois.isoc.org.il is the whois server but it returns all the domains as existant.

 

I know this is a long shot but i really hope theres some one who can help me or point me in the right direction!

TIA!!

Link to comment
https://forums.phpfreaks.com/topic/142374-checking-domain-availibility/
Share on other sites

Delete that server. Use:

<?php
// List of whois servers
$serverList[0]['top']      = 'com';
$serverList[0]['server']   = 'whois.crsnic.net';
$serverList[0]['response'] = 'No match for';
$serverList[0]['check']    = true;

$serverList[1]['top']      = 'net';
$serverList[1]['server']   = 'whois.crsnic.net';
$serverList[1]['response'] = 'No match for';
$serverList[1]['check']    = false;

$serverList[2]['top']      = 'org';
$serverList[2]['server']   = 'whois.publicinterestregistry.net';
$serverList[2]['response'] = 'NOT FOUND';
$serverList[2]['check']    = false;




    function checkDomain($domain,$server,$findText){
        // Open a socket connection to the whois server

        $con = fsockopen($server, 43);
        if (!$con) return false;
        
        // Send the requested doman name
        fputs($con, $domain."\r\n");
        
        // Read and store the server response
        $response = ' :';
        while(!feof($con)) {
            $response .= fgets($con,128); 
        }
        
        // Close the connection
        fclose($con);
        
        // Check the response stream whether the domain is available
        if (strpos($response, $findText)){
            return true;
        }
        else {
            return false;   
        }
    }

    function showDomainResult($domain,$server,$findText){
       if (checkDomain($domain,$server,$findText)){
          echo "<tr><td>$domain</td><td>AVAILABLE</td></tr>";
       }
       else echo "<tr><td>$domain</td><td>TAKEN</td></tr>";
    }
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.