<?php
error_reporting(0);
$domain = "mybroadband.co.za";
if(function_exists(curl_init)){
$result = cozacurlcheck($domain);
}else{
$result = cozasocketcheck($domain);
}
if($result){
echo "$domain has already been registered.";
}else{
echo "$domain is available for registration.";
}
// Function to check co.za whois via socket connection - Return true if taken or false if available
function cozasocketcheck($domain){
$errno = 0;
$errostr = "";
$timeout = 30;
$fp = fsockopen("co.za",80,$errno,$errstr,$timeout);
if($fp){
socket_set_timeout($fp,$timeout);
$url = "GET /cgi-bin/whois.sh?Domain=$domain HTTP/1.0\r\n Host: co.za\r\n";
$url .= "Connection: Keep-Alive\r\n User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)\r\n";
$url .= "Referer: http://co.za/whois.shtml\r\n Accept: text/plain, text/html\r\n\r\n";
fputs($fp,$url);
$output = "";
while(!feof($fp)){
$output .= fgets($fp,128);
}
fclose($fp);
$temp_code = strip_tags($output);
if(preg_match("/Match: One/i",$temp_code)){
//echo "The name is taken";
return 1;
}else{
//echo "The name is available";
return 0;
}
}else{
$layout = "<tr>\n<td>\nThe script could not connect to the co.za whois server<br>";
$layout .= "<b>DEBUG INFO:</b><br><br>";
$layout .= "Error No: $errno<br>Error Description:<br>$errstr</td>\n</tr>\n";
print_results($layout);
exit;
}
}
// Function to check co.za whois via curl - Return true if taken or false if available
function cozacurlcheck($domain){
$ch = curl_init();
$url = "http://co.za/cgi-bin/whois.sh?Domain=";
$url .= $domain;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_REFERER, "http://co.za/whois.shtml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if(curl_error($ch) == ""){
curl_close($ch);
$temp_code = strip_tags($data);
if(preg_match("/Match: One/i",$temp_code)){
//echo "The name is taken";
return 1;
}else{
//echo "The name is available";
return 0;
}
}else{
curl_close($ch);
$layout = "<tr>\n<td>\nAn Error Occured in connecting to the whois server</td>\n</tr>\n";
print_results($layout);
exit;
}
}
?>