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

Comments

Anonymous at 17 Apr, 2009 10:24
How we can install this script on our website ? i want to offer services on my website www.seomalaysia.my to sell domains so i need a script that can check availability of domain names. please if possible provide some information.

Reply to this.
sami meqbel at 31 May, 2009 03:15
also, i want to have it on my website to check the domain avialability.. plaese help
Reply to this.
Anonymous at 08 Jun, 2009 11:16
Didnt work at start but i had to strip the name 'domain' to get it work.

Change:

return (strpos($result, 'No match for domain') !== false);


Into:

return (strpos($result, 'No match for') !== false);

Savage
Reply to this.
Comment

Please dont enter you comments in this form - this is a fake form to confuse spamming bots. The next form is the real one.




Comment




Comment Formating : HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.
Subscribe to Feed