<?php
function checkDomain($domain_check,$server,$findText){
// Open a socket connection to the whois server
$con = fsockopen($server, 43);
if (!$con) return false;
// Send the requested doman name
fputs($con, $domain_check."\r\n");
// Read and store the server response
$response = ' :';
while(!feof($con))
{
$response .= fgets($con,128);
}
//echo $response;
// Close the connection
fclose($con);
// Check the response stream whether the domain is available
if (strpos($response, $findText))
{
return true;
}
else
{
return false;
}
}
function showDomainResult($domain_check,$server,$findText)
{
if (checkDomain($domain_check,$server,$findText))
{
class Emp {
public $domain = "";
public $availability = "";
}
$e = new Emp();
$e->domain = $domain_check;
$e->availability = "available";
echo json_encode($e);
}
else
{
class Emp {
public $domain = "";
public $availability = "";
}
$e = new Emp();
$e->domain = $domain_check;
$e->availability = "TAKEN";
echo json_encode($e);
}
}
?>
<?php
if ($_GET['domain'] != '')
{
list($domain_name, $tld) = explode(".", urldecode($_GET[domain]));
$tld_all = $tld;
$tld_main = $tld;
$server = "whois.verisign-grs.com";
$response = "No match for";
showDomainResult($domain_name.".".$tld_all,$server,$response);
}
?>