2

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.

mrpatg
  • 10,001
  • 42
  • 110
  • 169
  • What do you mean by "available"? Do you mean the machine the domain points at is up and running and therefore available for requests? Do you mean available as in "Nobody's registered this domain yet so it's available for purchase"? Something else? – GordonM Mar 11 '16 at 12:18

1 Answers1

5

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');
Tyler Carter
  • 60,743
  • 20
  • 130
  • 150