PHP Function to Function to Check Domain Availability

This function will check for the availability of the domain you gave as the argument. Note: This script will only work in Linux system - it uses the whois command to do the lookup.

Documentation

Example


$domain = 'bin-co.com';
if(checkDomainAvailability($domain)) {
	print "Domain '$domain' available.";
} else {
	print "Domain '$domain' NOT available. Sorry!";
}

Code

<?php

/**
 * This function will check for the availabilty of the domain you gave as the argument. Note: This 
 * script will only work in Linux system - it uses the whois command to do the lookup.
 * Argument: $domain - the name of the domain you want to check.
 * Return: Bolean - true if the domain is availabile - and false if its not.
 * http://www.bin-co.com/php/scripts/online/check_domain_availability/
 */
function checkDomainAvailability($domain) {
    if(
preg_match('/[;\&\|\>\<]/'$domain)) exit; //Could be a hack attempt
    
     
exec("whois " escapeshellarg($domain), $output); //:CAREFUL:
     
$result implode("\n"$output);
    
    return (
strpos($result'No match for domain') !== false);
}

License

BSD License, as always

blog comments powered by Disqus
Subscribe to Feed