Find out if a domain name exists

You can user CURL to request a page and evaluate the response to determine if the page exists.

function verify_domain($domain='') {
	$url = "http://" . $domain;
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_NOBODY, true);
	curl_exec($ch);
	$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);

	if($code >= 400) {
		return false;
	}

	return true;
}

Leave a Reply