Jump to content

php domain name lookup


robcrozier

Recommended Posts

hi everyone, im not at all sure if this is possible but what im trying to do is create a small program that looks up domain names and simply states whether they are available or not. I want to embed this as a small search field in my website to my users can discover very simply if the domain name they want is available.

If this is not possible with php - can anyone point me in the right direction.

Thanks
Link to comment
https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/
Share on other sites

Here is a simple method. all it does is check if your DNS server finds a IP for the domain, if it doesn't then the domain name is not taken. You have to be sure your DNS server is not caching the results, many use long cache times, so you will not get goof results if your DNS server is doing that.

Simple example...

[code]<?

// maximum domains to test

$max = 100;


$out = array ();
$ftc = 0;
$ntc = 0;

// we really don't need to do any testing for unsafe characters
// because we are only testing the domain name, so we just do a
// mild check

if ( isset ( $_POST['domains'] ) )
{
$test = preg_split ( "/\r?\n/", trim ( $_POST['domains'] ) );

foreach ( $test as $domain )
{
$domain = trim ( $domain );

if ( ! empty ( $domain ) && preg_match ( "/[a-z-0-9\.\-]/i", $domain ) )
{
if ( ( $ip = gethostbyname ( $domain ) ) != $domain )
{
$ftc++;

$out[0][] = array ( 'name' => $domain, 'ip' => $ip );
}
else
{
$ntc++;

$out[1][] = array ( 'name' => $domain );
}
}

if ( ++$max == 0 )
{
break;
}
}
}
?>
<html>
<head>
<title>Mass domain to ip</title>
</head>
<body>
<?
if ( ! empty ( $out ) )
{
echo 'Found domains ' . $ftc . '<br /><br />';
echo '<pre>';
print_r ( $out[0] );
echo '</pre>';
echo '<br /><br />Unused domains ' . $ntc . '<br /><br />';
echo '<pre>';
print_r ( $out[1] );
echo '</pre>';
echo '<br /><br />';
}
?>
<form name="FormName" action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<center><textarea name="domains" rows=20 cols=40 wrap="off"></textarea><br>
<input type="submit" value="Send"></center>
</form>
</body>
</html>[/code]


printf

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.