//check domain availability
if (isset($_POST['domain'])){
$domain = trim(strtolower($_POST['domain']));
$domain = str_replace("www.", "", $domain);
$domain = str_replace("http://", "", $domain);
//validate domain name
$domainValid = preg_match ("/^[a-z0-9][a-z0-9\-]+[a-z0-9]$/", $domain);
if (!$domainValid) $domain = ''; //invalidate it
$ext = strtolower($_POST[ext]);
$url=$domain.$ext;
switch($ext){
case ".co.uk":
$whois = "whois.nic.uk";
break;
case ".com":
case ".net":
$whois = "whois.verisign-grs.com";
break;
case ".org":
$whois = "whois.pir.org";
break;
case ".biz":
$whois = "whois.biz";
break;
case ".info":
$whois = "whois.afilias.info";
break;
case ".name":
$whois = "whois.nic.name";
break;
case ".uk.com":
case ".gb.com":
case ".uk.net":
case ".gb.net":
$whois = "whois.nomination.net";
break;
case ".eu.com":
$whois = "whois.centralnic.com";
break;
case ".cc":
$whois = "whois.nic.cc";
break;
default:
$whois = "whois.internic.com";
} //switch
$avail = 0;
if ($domain <> "") {
$f = fsockopen($whois, 43, $errno, $errstr, 30);
if (!$f) {
echo "Connection To Server Failed ($errno)";
} else {
fputs($f, "$url\r\n");
$who = '';
while (!feof($f)) {
$s = strtolower(fread($f,128));
$who .= $s;
$pos1 = strpos($who, 'no match');
$pos2 = strpos($who, 'not found');
if ($pos1 !== false) $avail = 1;
if ($pos2 !== false) $avail = 1;
}//while
fclose($f);
}//$f
if ($avail == 1){
$price = 100;//getPrice($ext);
$years = 2;//getYears($ext);
echo "<br /><p class=\"blue\">Congratulations <b>$url</b> is available!</p>\n<p>The price is £$price for $years year(s).</p>
<form action=\"\" method=\"post\">
<input type=\"hidden\" name=\"url\" value=\"$url\" />
<input type=\"hidden\" name=\"ext\" value=\"$ext\" />
<button type=\"submit\">Add to basket</button>
</form>";
} else {
echo "Sorry, <b>$url</b> is already registered.<br><br>Here is the whois data:<br>\r\n<pre>\r\n$who</pre>\r\n";
}//avail
}else{
echo "<p class=\"warn\">Invalid domain entered!</p>Please try again.";
}//($domain <> "")
}//post