1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with a little problem in a script

Discussion in 'PHP' started by gre, Mar 1, 2009.

  1. #1
    I have a a script that search whois and give respond if a domain is free or not. The problem is that im only able to search one domain a time,

    Works
    digitalpoint.com

    Not working
    digitalpont.com
    digitalpoint.com


    How do i do to make is search several domains?
     
    gre, Mar 1, 2009 IP
  2. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Use a loop.
     
    qualityfirst, Mar 1, 2009 IP
  3. gre

    gre Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I did try but couldnt find how to input it in right way. Maybe you could help me with it? Its a really short code so should be easy for some one who knows.
     
    gre, Mar 1, 2009 IP
  4. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Post it here and I'll take a look.
     
    qualityfirst, Mar 1, 2009 IP
  5. gre

    gre Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There you have it.
    <?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 "<div>$domain - Available</div>";
    }
    else echo "<div>$domain - Taken</div>";
    }
    ?>
    
    Search
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain" id="domain">
    <textarea name="domainname" id="comment" cols="50%" rows="10" tabindex="4"></textarea>
    <br />
    <input type="checkbox" name="all"/>All
    <input type="checkbox" name="com" checked />.com
    <input type="checkbox" name="net"/>.net
    <input type="checkbox" name="org"/>.org
     <br/>
    <input class="text" type="submit" name="submitBtn" value="Search"/>
    </form>
    
    <?php
    if (isset($_POST['submitBtn'])){
    $domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
    $d_all = (isset($_POST['all'])) ? 'all' : '';
    $d_com = (isset($_POST['com'])) ? 'com' : '';
    $d_net = (isset($_POST['net'])) ? 'net' : '';
    $d_org = (isset($_POST['org'])) ? 'org' : '';
    
    // Check domains only if the base name is big enough
    if (strlen($domainbase)>0){
    ?>
    <br />
    <strong>Searched domains</strong>
    <div id="result">
    <?php
    if (($d_com != '') || ($d_all != '') ) showDomainResult($domainbase.".com",'whois.crsnic.net','No match for');
    if (($d_net != '') || ($d_all != '') ) showDomainResult($domainbase.".net",'whois.crsnic.net','No match for');
    if (($d_org != '') || ($d_all != '') ) showDomainResult($domainbase.".org",'whois.publicinterestregistry.net','NOT FOUND');
    
    ?>
    </div>
    </div>
    <?php
    }
    }
    ?>
    </body>
    PHP:
     
    gre, Mar 1, 2009 IP