1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Domain Availability Checker?

Discussion in 'PHP & Perl' started by muchacho, Mar 23, 2011.

  1. muchacho

    muchacho Supreme Member

    Joined:
    May 14, 2009
    Messages:
    1,293
    Likes Received:
    187
    Location:
    Lancashire, England.
    I found 2, but both created loads of errors when ran on 'Easy PHP'.

    I have no idea whether it's an error in the code, the fact I'm using Windows 7 64 bit, or because of a problem with Easy PHP, but was thinking if anybody could please check the code out and/or suggest any alternatives? Just a simple PHP script where I can paste hundreds of keywords in and it'll fire back if they're available for .ext such as org com net co.uk etc.

    Code:
    <?php
    /*    * PHP Exact Phrase Finder: Coded by Erik (aka TheGoat) for my friends at BHW.
        *
        * 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 2
        * of the License, or any later version. 
        * YOU MAY NOT SELL THIS SOFTWARE!!!!!!
        *
        * 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.
        *
        * A copy of the GNU General Public License is not distributed 
        * with this program; If you would like one, write to the Free Software
        * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    */
    ?>
    <html>
    <head>
    <title>Exact Phrase Finder</title>
    </head>
    
    <body>
    <div align="center">
    <?php
    set_time_limit(9999999);
    
    ob_start();
    
    function chkDomain($domain,$whoisServer,$textToFind)
    {
        // Create a socket
        $socketConnection = fsockopen($whoisServer, 43);
        if (!$socketConnection) return false;
            
        // Query the server with domain
        fputs($socketConnection, $domain."\r\n");
            
        // Read and store the server response
        $serverResponse = ' :';
        while(!feof($socketConnection)) 
        {
            $serverResponse .= fgets($socketConnection,128); 
    //        echo $serverResponse;
        }
            
        // Close the socket
        fclose($socketConnection);
            
        // Check if the domain is available
        if (strpos($serverResponse, $textToFind) || strpos($serverResponse, "No match for") || strpos($serverResponse, "NOT FOUND"))
        {
            return true;
        }
            else
        {
            return false;   
        }
    }
    
    // You must add an array element here for any additional TLDs.
    $TLD["com"] = array('server' => "whois.crsnic.net",
                        'text' => "No match for");
    
    $TLD["org"] = array('server' => "whois.publicinterestregistry.net",
                        'text' => "No match for");
    
    $TLD["net"] = array('server' => "whois.crsnic.net",
                        'text' => "No match for");
                        
    $TLD["info"] = array('server' => "whois.afilias.info",
                        'text' => "NOT FOUND");
    
    $TLD["co"] = array('server' => "whois.nic.co",
                        'text' => "Not found");
    
    $TLD["co.uk"] = array('server' => "whois.nic.uk",
                        'text' => "No match for");
        
    // check if form has been submitted
    if (!isset($_POST['submit']))
    {
        // if not display form
    
        echo "Select from the TLDs below: <br />
    
    <form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"POST\">
    
    com: <input type=\"checkbox\" value=\"com\" name=\"options[]\">    
    org: <input type=\"checkbox\" value=\"org\" name=\"options[]\">    
    net: <input type=\"checkbox\" value=\"net\" name=\"options[]\">    
    co: <input type=\"checkbox\" value=\"co\" name=\"options[]\">    
    co.uk: <input type=\"checkbox\" value=\"uk\" name=\"options[]\">    
    info: <input type=\"checkbox\" value=\"info\" name=\"options[]\">
    
    <br /><br />
    check with dashes: <input type=\"checkbox\" name=\"dashes\">
    <br /><br />
    One search term per line.
    <br />
    
    <textarea name=\"terms\" cols=80 rows=20 wrap=\"off\"></textarea><br />
    <br /><br />
    
    Capture data from a .csv file: <input type=\"checkbox\" name=\"adwords\"> &nbsp&nbsp delimeter: <input size=1 maxlength=1 type=\"text\" name=\"delimeter\" />
    <br /><br />
    
    <input type=\"submit\" name=\"submit\" value=\"Check Domains\">
    
    </form>";
    
    // output buffer
    for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
    
    }
    
    
    else
    { 
        echo "<div align=\"left\">";
        // form has been submitted
        // check if any items were selected
        // if so display them
        if (is_array($_POST['options']))
        {
            $TLDCount = count($_POST['options']);
            echo "Will scan $TLDCount TLD(s): <br />";
            
            // output buffer
            for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
    
            //use a foreach() loop to read and display TLDs
            foreach ($_POST['options'] as $opt)
            {
                echo "<i>$opt</i><br />\n";
            } 
    
            // initialize check the adwords value
            if (isset($_POST['adwords']))
            {
                $delimeter = $_POST['delimeter'];
                
                echo "\n<br />Checking the Adwords .csv file: <br /><br/>\n";
                $adword_line = split("\n", $_POST['terms']); // create array from input, split be linespace
                $uid = 0; // set id
                foreach ($adword_line as $term_line)
                {
                    /* for some reason, an encoded line brake is added at the end of the
                    first occurence of the loop. Very odd... but just strip it out for now... */
                    $term_line = trim($term_line);
                    if($term_line==NULL) { continue; }                
                    echo "<i>$uid</i> - " . $term_line . "<br />\n";
                    $columns = explode("$delimeter", $term_line); // set delimeter and split into array
                    $cl_count = count($columns); // count the number of columns
                    echo "$cl_count columns in line $uid<br />";
                    echo "$columns[0]<br />";
                    
                    $term_name = $columns[0];
                    
                    $domain = str_replace(" ", "", "$term_name"); // Delete whitespace to create 2nd level domain portion
                    // loop TLDs for each domain
                    foreach ($_POST['options'] as $opt) 
                    {
                        $fqdn = $domain . "." . $opt; // create FQDN from seperate domain portions
                        $whois_server = $TLD["$opt"]["server"]; // assign whois server
                        $find_text = $TLD["$opt"]["text"]; // assign unique string to find
        
                        if (chkDomain("$fqdn","$whois_server","$find_text")) // check if domain is availale
                        {
                            echo "<strong/>$fqdn = available</strong><br />\n";
                            $available[] = $fqdn;
                            $keynames[] = "$fqdn,$term_line";
                        }
                        else
                        {
                            echo "$fqdn = taken<br />\n";
                        } 
                        // output buffer
                        for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
                    }     
                    $numWords = count(explode(" ",$term_name)); // count the number of words in each term
                    if ($numWords > 1 && isset($_POST['dashes']))
                    {
                        $domain = str_replace(" ", "-", "$term_name"); // Replace whitespace with a '-'
                        //use a foreach() loop TLDs
                        foreach ($_POST['options'] as $opt)
                        {
                            $fqdn = $domain . "." . $opt;
                            $whois_server = $TLD["$opt"]["server"];
                            $find_text = $TLD["$opt"]["text"];
        
                            if (chkDomain("$fqdn","$whois_server","$find_text"))
                            {
                                echo "<strong/>$fqdn = available</strong><br />\n";
                                $available[] = $fqdn;
                                $keynames[] = "$fqdn,$term_line";
                            }
                            else
                            {
                                echo "$fqdn = taken<br />\n";
                            }
                        
                            // output buffer
                            for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
                        } 
                    }
                    echo "<br />\n";
        
                    // output buffer
                    for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
                    $uid++;
                }
                if(count($available) > 0);
                {
                    echo "<br />
                    <br />
                    Found these available domains:<br />";
                    foreach ($available as $found_domain)
                    {
                        echo "<strong>$found_domain</strong><br />\n";
                    }
                    
                    echo "<br /><br />
                    <table width='100%'>";
                    
                    //loop through all the input again gain
                    foreach ($keynames as $key_line)
                    { 
                        echo "<tr>";
                        $blocks = explode("$delimeter", $key_line); // set delimeter and split into array
                        //echo "$key_line" . "<br />";
                        
                        foreach ($blocks as $col)
                        {
                            echo "<td>$col</td>";
                        }
                        echo "</tr>";
                    }
                    echo "</table>";
                }
            }
            
            else
            {
                echo "\n<br />Checking the search terms: <br /><br/>\n";
                $search_terms = split("\n", $_POST['terms']); // create array from input, split be linespace
                $search_terms = array_unique($search_terms); // remove duplicates
            
                foreach ($search_terms as $term_name)
                {
                    /* for some reason, an encoded line brake is added at the end of the
                    first occurence of the loop. Very odd... but just strip it out for now... */
                    $term_name = trim($term_name);
    
                    echo "<i>$term_name</i><br />\n";
                    $domain = str_replace(" ", "", "$term_name"); // Delete whitespace to create 2nd level domain portion
                    // loop TLDs for each domain
                    foreach ($_POST['options'] as $opt) 
                    {
                        $fqdn = $domain . "." . $opt; // create FQDN from seperate domain portions
                        $whois_server = $TLD["$opt"]["server"]; // assign whois server
                        $find_text = $TLD["$opt"]["text"]; // assign unique string to find
        
                        if (chkDomain("$fqdn","$whois_server","$find_text")) // check if domain is availale
                        {
                            echo "<strong/>$fqdn = available</strong><br />\n";
                            $available[] = $fqdn;
                        }
                        else
                        {
                            echo "$fqdn = taken<br />\n";
                        } 
                        // output buffer
                        for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
                    }     
                    $numWords = count(explode(" ",$term_name)); // count the number of words in each term
                    if ($numWords > 1 && isset($_POST['dashes']))
                    {
                        $domain = str_replace(" ", "-", "$term_name"); // Replace whitespace with a '-'
                        //use a foreach() loop TLDs
                        foreach ($_POST['options'] as $opt)
                        {
                            $fqdn = $domain . "." . $opt;
                            $whois_server = $TLD["$opt"]["server"];
                            $find_text = $TLD["$opt"]["text"];
        
                            if (chkDomain("$fqdn","$whois_server","$find_text"))
                            {
                                echo "<strong/>$fqdn = available</strong><br />\n";
                                $available[] = $fqdn;  
                            }
                            else
                            {
                                echo "$fqdn = taken<br />\n";
                            }
                        
                            // output buffer
                            for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
                        } 
                    }
                    echo "<br />\n";
        
                    // output buffer
                    for($i=0;$i<1;$i++) { ob_flush(); flush(); usleep(300000); }
                }
                if(count($available) == 0);
                {
                    echo "<br />
                    <br />
                    Found these available domains:<br />";
                    foreach ($available as $found_domain)
                    {
                        echo "<strong>$found_domain</strong><br />\n";
                    }
                }            
            }
        }
        else
        {
            echo "Nothing selected\n";
        }
    echo "</div>";
    }
    ?>
    </div>
    </body>
    </html>
    
    The errors it brings back include things such as:

    Code:
    [B]Deprecated[/B]:  Function split() is deprecated in [B]C:\Program Files (x86)\EasyPHP-5.3.6.0\www\epf\index.php[/B] on line [B]248[/B]
     
    Last edited: Mar 23, 2011
  2. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    The Deprecated message is just a warning that some functions will
    not be available in future versions of PHP.

    Stick this line after the first <?php
    Code:
    error_reporting(E_ALL & ~E_DEPRECATED);
    and it should stop reporting the warnings.

    That will allow you to see if there are any actual errors.
     
    • Thanks Thanks x 1
  3. muchacho

    muchacho Supreme Member

    Joined:
    May 14, 2009
    Messages:
    1,293
    Likes Received:
    187
    Location:
    Lancashire, England.
    There still seems to be many errors.

    Another error msg I'm seeing is:

    Code:
    [B]Warning[/B]:  fsockopen() [[URL="http://127.0.0.1:8888/epf/function.fsockopen"]function.fsockopen[/URL]]: unable to connect to :43 (No connection could be made because the target machine actively refused it. ) in [B]C:\Program Files (x86)\EasyPHP-5.3.6.0\www\epf\index.php[/B] on line [B]42[/B]
    If anybody could perhaps please copy the code in the OP and run it, you might be able to fix the code so that it works?

    It would be a great tool if it worked, as I'm paranoid of checking domains at places such as GoDaddy.
     
  4. zelma143

    zelma143 Power Member

    Joined:
    Jun 25, 2010
    Messages:
    571
    Likes Received:
    37
    Occupation:
    PHP programmer,Bot maker,iMacro script maker
    hey ..

    find
    PHP:
     if(count($available) == 0
    replace with

    PHP:
     if(trim(count($available)) === 0
    enjoy it ..!!
     
    • Thanks Thanks x 2
  5. muchacho

    muchacho Supreme Member

    Joined:
    May 14, 2009
    Messages:
    1,293
    Likes Received:
    187
    Location:
    Lancashire, England.
    Thanks for that. It doesn't output it in a table which is how it's supposed to work but at the bottom it does tell me which are available, which is the important bit.

    If anyone can get it working and outputting in a neat table that would be a bonus.

    As things stand it displays these errors...
    HTML:
    Will scan 6 TLD(s): 
    com
    org
    net
    co
    uk
    info
     
    Checking the search terms: 
    
    widget
    widget.com = taken
    widget.org = taken
    widget.net = taken
    widget.co = taken
    
    Notice:  Undefined index: uk in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\epf\index.php on line 270
    
    Notice:  Undefined index: uk in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\epf\index.php on line 271
    
    Warning:  fsockopen() [function.fsockopen]: unable to connect to :43 (No connection could be made because the target machine actively refused it. ) in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\epf\index.php on line 42
    widget.uk = taken
    widget.info = taken
    
    widget logic
    widgetlogic.com = taken
    widgetlogic.org = available
    widgetlogic.net = available
    widgetlogic.co = available
    It does the same for every one of the keywords checked with the .ext before displaying at the bottom...

    HTML:
    Found these available domains:
    widgetlogic.org
    widgetlogic.net
    etc....
    So it's still displaying errors and not giving me a nice output, but the information is given at the bottom.
     
  6. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    Change your error reporting to something like

    Code:
    error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
    
    http://php.net/manual/en/function.error-reporting.php