Pages

Verify If Domain Really Exists

Snippet Name: Verify If Domain Really Exists

Description: This script checks to see if a domain is present and reachable on the internet.



 <?php
 
function url_exists($strURL) {
    $resURL = curl_init();
    curl_setopt($resURL, CURLOPT_URL, $strURL);
    curl_setopt($resURL, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($resURL, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback');
    curl_setopt($resURL, CURLOPT_FAILONERROR, 1);
 
    curl_exec ($resURL);
 
    $intReturnCode = curl_getinfo($resURL, CURLINFO_HTTP_CODE);
    curl_close ($resURL);
 
    if ($intReturnCode != 200 && $intReturnCode != 302 && $intReturnCode != 304) {
       return false;
    } else {
        return true;
    }
}
 
 
 
 
OR.................
 
function is_valid_url($url)
{
    $url = preg_replace('~^https?://~i', null, $url);
    return @checkdnsrr($url);
}
 
?>

No comments:

Post a Comment