co.za domain check PHP script

MeercatMilker

Well-Known Member
Joined
Feb 24, 2006
Messages
186
Reaction score
5
Hi guys,

Can someone please share some PHP code with me that is able to check the availability of a co.za domain name?

I basically just need a reliable way to check if a certain co.za domain is available for registration using PHP.
 
I figured it out. Here is the script I made should anyone else need this in the future:

PHP:
<?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;
	}
}
	
?>
 
would it be able to alter this script so you can add multiple domains to be checked?
 
Just loop through the domains one by one. You cant query multiple domains in one connection to co.za

Hmmm, well, what I'm looking for is the possibility to paste a list of domain names and then having the script automatically go through the list and give me a report on everything at the end.

I think theres a limit of 5 or 10 queries per minute from the same ip, so some kind of delay would have to be added to the script.
 
Hmmm, well, what I'm looking for is the possibility to paste a list of domain names and then having the script automatically go through the list and give me a report on everything at the end.

I think theres a limit of 5 or 10 queries per minute from the same ip, so some kind of delay would have to be added to the script.

Yes, that is true. If you do one domain every minute you should not trigger the data mining detection. You can easily delay the script after every loop and play with the duration until you can reliably get it to work for any quantity of domains you want to check.

You will have to change the execution time of the script so that it doesn't timeout after 30secs though.
 
Yes, that is true. If you do one domain every minute you should not trigger the data mining detection. You can easily delay the script after every loop and play with the duration until you can reliably get it to work for any quantity of domains you want to check.

You will have to change the execution time of the script so that it doesn't timeout after 30secs though.

I don't know much about coding though. If anyone would be willing to alter the script to be able to do bulk domain name checking for me, something that I can let run just before bed or something, that would be really awesome. I'd be willing to pay for the script even, as long as your price is reasonable.
 
I want to be able to find good domains for SEO purposes. The domain name matters quite a bit in terms of SEO, so having the keyword in it can help a lot. But checking them one by one is really tedious, thats why I want the script
 
Ok, so you will enter the domain names you have in mind manually into a list for the script to check? That would be very simple and I can send you something like that tomorrow.

I you want a script that automatically mix and match a bunch of keywords together then you are talking about a serious amount of work. For example if you give it a dictionary file full of words and you then want to check combinations of those words for availability you talk about a more complex script.
 
Yeah I'll make the list, thats chilled. Sorry was away from my pc for a while. Thanks for the help man :D
 
Try this

PHP:
<?php

echo "<form method=\"post\" name=\"edit\" action=\"cpanel.php\" />
            Domain Name:
 
            <input type=\"text\" name=\"domain\" value=\"\" />
            <br/>

            <input type=\"submit\" name=\"Submit\" value=\"Check\" />
            
            </form>";
        
        if(isset($_POST['domain'])){
        
            
        
            $domain_name = $_POST['domain'];
            $domain_name_no_space = str_replace(" ","",$domain_name);
                
            $contents = file_get_contents("http://co.za/cgi-bin/whois.sh?Domain=$domain_name_no_space");
            if (strpos($contents, 'No Matches') !== false) {
                echo $domain_name_no_space . ".co.za is not taken";
            }
            else{
                echo $domain_name_no_space . ".co.za is taken";
            }

                    
        
        
        }
        
        else{
            echo "Please enter domain name";
        }
 
Last edited:
If you are using Linux, then use whois on the command line.

$ whois qwrqw.co.za | head -1
Available

$ whois mybroadband.co.za | head -1
Domain Name: mybroadband.co.za

If you need it in a PHP script, call the whois application.
 
Last edited:
use the whois command instead as mentioned. but I get the feeling OP is no programmer and wants **** done for him for free
 
Top
Sign up to the MyBroadband newsletter
X