Jump to content

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.