adding more domains to domain check script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
virgild
Forum Newbie
Posts: 3
Joined: Tue Dec 08, 2009 4:04 pm

adding more domains to domain check script

Post by virgild »

Hello all! I can't figure out how to do something.. I tried but I get errors/

I am using a script to check domains on whois but I can only see if .com is available. How can I add .net, .org and such?

The script is

Code: Select all

<?php
    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>&nbsp;AVAILABLE</td></tr>";
       }
       else echo "<tr><td>$domain</td><td>&nbsp;TAKEN</td></tr>";
    }
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<link href="formstyle.css" rel="stylesheet" type="text/css" />
<body>
     <div id="container"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain">
        <strong>Domain name</strong>
<table>
  <tr><td><input name="domainname" type="text" /></td></tr>
          <tr><td><input type="checkbox" name="com" checked/>.com</td></tr>
          <tr><td><input type="submit" name="submitBtn" value="Check domain"/></td></tr>
        </table>  
      </form>
<?php    
    // The form was submitted
    if (isset($_POST['submitBtn'])){
        $domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
        $d_com      = (isset($_POST['com'])) ? 'com' : '';
        
        // Check domains only if the base name is big enough
        if (strlen($domainbase)>0){
            echo '<table>';
            if ($d_com != '')  
               showDomainResult($domainbase.".com",
    'whois.crsnic.net','No match for');
            echo '</table>';
        }
    }
?> </div>   
</body>  
virgild
Forum Newbie
Posts: 3
Joined: Tue Dec 08, 2009 4:04 pm

Re: adding more domains to domain check script

Post by virgild »

bump :wink:
Post Reply