help out with my php script

Discussion in 'PHP' started by hakimade, Jun 6, 2010.

  1. #1
    i have the following whois lookup script,that can check check the availablity of a domain my problem with the script is that the script comes back with domain name taken even if the domain is available.can anybody help me out??

    
    
    <?php
    $domain = $_GET['domain'];
    $ext = $_GET['ext'];
    
    //Domain Checker
    function check_domain($domain,$ext){
        $server="whois.networksolutions.com";
        $nomatch="No match for";
    
        $output="";
        if(($sc = fsockopen($server,43))==false){
            return true;
        }
        fputs($sc,"$domain.$ext\n");
        while(!feof($sc)){
            $output.=fgets($sc,128);
        }
        fclose($sc);
        echo $output;
        if (eregi($nomatch,$output))
        {
            return true;
        } else {
            return false;
        }
    }
    
    //Sample usage
    $is_registered = check_domain($domain , $ext);
    if($is_registered == true){ echo "Domain Taken";}else{echo "Domain is free";}
    
    ?>
    
    
    Code (markup):
    that is the domain.php file

    
    
    <html>
    <head>
    <title>Domain Age Calculator</title>
    <script language="javascript" type="text/javascript">
    //Browser Support Code
    function ajaxFunction(){
        var ajaxRequest;  // The variable that makes Ajax possible!
       
        try{
            // Opera 8.0+, Firefox, Safari
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            // Internet Explorer Browsers
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    // Something went wrong
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){
                var ajaxDisplay = document.getElementById('ajaxDiv');
                ajaxDisplay.innerHTML = ajaxRequest.responseText;
            }
        }
        var domain = document.getElementById('domain').value;
        var ext = document.getElementById('ext').value;
       
        var queryString = "?domain=" + domain + "&ext=" + ext;
        ajaxRequest.open("GET", "domain.php" + queryString, true);
        ajaxRequest.send(null);
    }
    
    </script>      
    </head>
    <body>
    <input type="text" size="30" name="domain" id="domain">
    <select name="ext" id="ext">
        <option value="">select extension</option>
        <option value="com">com</option>
        <option value="org">org</option>
        <option value="net">net</option>
        <option value="info">info</option>
        <option value="edu">edu</option>   
    </select>
    <input type="button" value="Check" onclick="ajaxFunction()"><br><br>
    <b>Enter the domain name without www. Correct</b> = gmail.com <b>Wrong</b> = www.gmail.com
    <br><br>
    <div id="ajaxDiv">The Message will be shown here</div>
    </body>
    </html>
    
    
    
    Code (markup):

     
    hakimade, Jun 6, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    networksolutions where made a disgrace of before, people used to look up available names and low and behold when you search again they had registered it and if you wanted it, you had to pay more, maybe they are doing this again ?
     
    MyVodaFone, Jun 6, 2010 IP
  3. definitely

    definitely Well-Known Member

    Messages:
    520
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    160
    #3
    did this script work earlier or you just pulled it from somewhere on the internet, if so, give a reference, so we can understand where exactly the error (or not) is.
     
    definitely, Jun 6, 2010 IP
  4. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Might want to check out file_get_contents

    php.net/manual/en/function.file-get-contents.php
     
    qrpike, Jun 6, 2010 IP
  5. hakimade

    hakimade Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i have the following whois look-up script,that should check the availability of a domain my problem with the script is that the script comes back with domain name taken even if the domain is not available.can anybody help me out??

    The html code:(
    
    <html>
    <head>
    <title>Domain Age Calculator</title>
    <script language="javascript" type="text/javascript">
    //Browser Support Code
    function ajaxFunction(){
        var ajaxRequest;  // The variable that makes Ajax possible!
       
        try{
            // Opera 8.0+, Firefox, Safari
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            // Internet Explorer Browsers
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    // Something went wrong
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){
                var ajaxDisplay = document.getElementById('ajaxDiv');
                ajaxDisplay.innerHTML = ajaxRequest.responseText;
            }
        }
        var domain = document.getElementById('domain').value;
        var ext = document.getElementById('ext').value;
       
        var queryString = "?domain=" + domain + "&ext=" + ext;
        ajaxRequest.open("GET", "domain.php" + queryString, true);
        ajaxRequest.send(null);
    }
    
    </script>      
    </head>
    <body>
    <input type="text" size="30" name="domain" id="domain">
    <select name="ext" id="ext">
        <option value="">select extension</option>
        <option value="com">com</option>
        <option value="org">org</option>
    
        <option value="net">net</option>
        <option value="info">info</option>
        <option value="edu">edu</option>   
    </select>
    <input type="button" value="Check" onclick="ajaxFunction()"><br><br>
    <b>Enter the domain name without www. Correct</b> = gmail.com <b>Wrong</b> = www.gmail.com
    
    <br><br>
    <div id="ajaxDiv">The Message will be shown here</div>
    </body>
    </html>
    
    Code (markup):
    save as domain.php
    
    
    <?php
    
    $firstdomain = $_GET['domain'];
    $ext = $_GET['ext'];
    
    $domain = $firstdomain.$ext;
    
    
    class whois {
    
    public $ext = array(
    '.com' => array('whois.crsnic.net','No match for'),
    '.net' => array('whois.crsnic.net','No match for'),
    '.org' => array('whois.publicinterestregistry.net','NOT FOUND'),
    '.us' => array('whois.nic.us','Not Found'),
    '.biz' => array('whois.biz','Not found'),
    '.info' => array('whois.afilias.net','NOT FOUND'),
    '.eu' => array('whois.eurid.eu','FREE'),
    '.mobi' => array('whois.dotmobiregistry.net', 'NOT FOUND'),
    '.tv' => array('whois.nic.tv', 'No match for'),
    '.in' => array('whois.inregistry.net', 'NOT FOUND'),
    '.co.uk' => array('whois.nic.uk','No match'),
    '.co.ug' => array('wawa.eahd.or.ug','No entries found'),
    '.or.ug' => array('wawa.eahd.or.ug','No entries found'),
    '.sg' => array('whois.nic.net.sg','NOMATCH'),
    '.com.sg' => array('whois.nic.net.sg','NOMATCH'),
    '.per.sg' => array('whois.nic.net.sg','NOMATCH'),
    '.org.sg' => array('whois.nic.net.sg','NOMATCH'),
    '.com.my' => array('whois.mynic.net.my','does not Exist in database'),
    '.net.my' => array('whois.mynic.net.my','does not Exist in database'),
    '.org.my' => array('whois.mynic.net.my','does not Exist in database'),
    '.edu.my' => array('whois.mynic.net.my','does not Exist in database'),
    '.my' => array('whois.mynic.net.my','does not Exist in database'),
    '.nl' => array('whois.domain-registry.nl','not a registered domain'),
    '.ro' => array('whois.rotld.ro','No entries found for the selected'),
    '.com.au' => array('whois.ausregistry.net.au','No data Found'),
    '.ca' => array('whois.cira.ca', 'AVAIL'),
    '.org.uk' => array('whois.nic.uk','No match'),
    '.name' => array('whois.nic.name','No match'),
    '.ac.ug' => array('wawa.eahd.or.ug','No entries found'),
    '.ne.ug' => array('wawa.eahd.or.ug','No entries found'),
    '.sc.ug' => array('wawa.eahd.or.ug','No entries found'),
    '.ws' => array('whois.website.ws','No Match'),
    '.be' => array('whois.ripe.net','No entries'),
    '.com.cn' => array('whois.cnnic.cn','no matching record'),
    '.net.cn' => array('whois.cnnic.cn','no matching record'),
    '.org.cn' => array('whois.cnnic.cn','no matching record'),
    '.no' => array('whois.norid.no','no matches'),
    '.se' => array('whois.nic-se.se','No data found'),
    '.nu' => array('whois.nic.nu','NO MATCH for'),
    '.com.tw' => array('whois.twnic.net','No such Domain Name'),
    '.net.tw' => array('whois.twnic.net','No such Domain Name'),
    '.org.tw' => array('whois.twnic.net','No such Domain Name'),
    '.cc' => array('whois.nic.cc','No match'),
    '.nl' => array('whois.domain-registry.nl','is free'),
    '.pl' => array('whois.dns.pl','No information about'),
    '.pt' => array('whois.dns.pt','No match')
    );
    
    public $error;
    
    function available($domain){
    $domain = trim($domain);
    if (eregi('^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$',$domain) != 1){
    $error = 'Invalid domain (Letters, numbers and hypens only) ('.$domain.')';
    return false;
    }
    preg_match('@^(http://www\.|http://|www\.)?([^/]+)@i', $domain, $preg_metch_result);
    $f_result = '';
    $domain = $preg_metch_result[2];
    $domain_name_array = explode('.', $domain);
    $domain_domain = strtolower(trim($domain_name_array[count($domain_name_array)-1]));
    $ext_in_list = false;
    
    if (array_key_exists('.'.$domain_domain, $this->ext)){
    $ext_in_list = true;
    }
    
    if(strlen($domain) > 0 && $ext_in_list){
    $server = '';
    $server = $this->ext['.' .$domain_domain][0];
    $lookup_result = gethostbyname($server);
    
    if ($lookup_result == $server){
    $error = 'Error: Invalid extension - '.$domain_domain.'. / server has outgoing connections blocked to '.$server.'.';
    return false;
    }
    
    $fs = fsockopen($server, 43,$errno,$errstr,10);
    
    if (!$fs || ($errstr != "")){
    $error = 'Error: ('.$server.') '.$errstr.' ('.$errno.')';
    return false;
    }
    
    fputs($fs, "$domain\r\n");
    while( !feof($fs) ) {
    $f_result .= fgets($fs,128);
    }
    
    fclose($fs);
    
    if($domain_domain == 'org'){
    nl2br($f_result);
    }
    
    if(eregi($this->ext['.'.$domain_domain][1], $f_result)){
    return true;
    } else {
    return false;
    }
    
    } else {
    $error = 'Invalid Domain and/or TLD server entry does not exist';
    }
    return false;
    }
    
    }
    
    
    
    $whois = new whois;
    $result = $whois->available($domain);
    
    if($result == false)
    { 
    echo "Domain is free";
    }
    else
    {
    echo "Domain Taken";
    }
    
    ?>
    
    
    Code (markup):
     
    hakimade, Jun 26, 2010 IP