Check Domain availability using cURL
In this article, I will explain how to Check Domain availability using cURL and PHP.
The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close().
In this article, I will explain how to Check Domain availability using cURL and PHP.
The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close().
$domain_name="Mydomain.com";
$domain= 'http://'.$domain_name;
$ch = curl_init($domain);
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
//The CURLOPT_RETURNTRANSFER option ensure that when I run curl_exec I get the result.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
if(curl_errno($ch))
{
return 'The domain is available!';
} else {
return 'The domain is not available';
}
// Close
curl_close($ch);
?>