tags:

views:

51

answers:

1

I cannot find a working php domain availability function that can check if a domain is available or not, and then define a $status variable with available or unavailable, so i can include it in my message.

Any tips on how to do this? Ive tried various native php functions like getdnsrr and others, but cannot get them to work. I simply need to define $status, as available, or unavailable.

Thanks for the help.

+2  A: 

Google Result

<?php
// Function to check response time
function pingDomain($domain){
    $starttime = microtime(true);
    $file      = fsockopen ($domain, 80, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;  // Site is down
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }
    return $status;
}
?>

Returns the Time it took to ping the server.
http://www.tutcity.com/view/check-your-server-status-a-basic-ping.10248.html


To Check if a domain is avaiable:

 <?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;   
        }
    }
?>

$status = checkDomain("stackoverflow.com",'whois.crsnic.net','No match for');
Chacha102
good tip but i need to determine if the domain is registered or not
Patrick
Oh, then one sec.
Chacha102
You win 20,000 internets. I wish there was a hug button on SO cause id be pushing it right now. Much thanks.
Patrick