Thought I would share this bit of code with everyone.

Discussion in 'PHP' started by exodus, Jun 23, 2007.

  1. #1
    I asked for help with this problem in the other thread listed here. I thought I would share the code that I was helped create. The function used is the last bit of information I needed to complete the domain check routine I was trying to do. :) Look it over and let me know what you think. Do you think it could be coded better? Post back something you would have done different.

    <?php
    
    set_time_limit(0);
    ob_start();
    
    function MakePairs($num_array) {
        $pairs = array();
        foreach($num_array as $outer) {
            foreach($num_array as $inner) {
            
                if($outer != $inner)
                    $pairs[] = trim($outer).trim($inner).".com";
            }
        }
       
        return $pairs;
    }
    
    
    function say($str) 
    {
      echo $str;
      ob_flush();
      flush();
      return;
    }
    
    function sayln($str)
    {
      echo $str."<br />";
      ob_flush();
      flush();
      return;
    }
    
    if(isset($_POST['submit']))
    { 
    
       sayln('Checking for free domains :) Wee...');
       $domains = explode("\n", $_POST['domains']); 
       $newpairs = MakePairs($domains);
       $num = count($newpairs);
       sayln("checking ".$num." domains");
     foreach($newpairs as $domain)
     {
         $domain = trim($domain);
         
         sayln("Checking: $domain");
         
         $buffer = null;       
         $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,"whois.crsnic.net:43");
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_TIMEOUT, 10);
          curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "$domain\r\n");
         $buffer = curl_exec($ch);
         curl_close($ch);
         
         if(eregi('No match for', $buffer)) 
          {
            $found[] = $domain;
            //sayln($domain);
          }
           
     }
     sayln("<pre>");
     print_r($found);
     sayln("</pre>");
    }  
    else { ?>
    
    <div style="text-align: center">
        <form action="index2.php" method="post">
            <textarea name="domains" cols="100" rows="20"></textarea>
            <br /><input type="submit" name="submit" value="Check For Free Domains" style="font-size: 30pt;" />
        </form>
    </div>
    <?php
    } 
    ?> 
    
    Code (markup):
     
    exodus, Jun 23, 2007 IP
  2. leede

    leede Guest

    Messages:
    3,381
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    0
    #2
    thanks for sharing, I will try it.
     
    leede, Jun 23, 2007 IP