robcrozier Posted January 7, 2007 Share Posted January 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/ Share on other sites More sharing options...
printf Posted January 7, 2007 Share Posted January 7, 2007 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 checkif ( 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 Quote Link to comment https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/#findComment-155190 Share on other sites More sharing options...
magic2goodil Posted January 7, 2007 Share Posted January 7, 2007 Simpler example, but not as effective as printf's I would think.[code]<?php$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); echo $hostname;?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/#findComment-155193 Share on other sites More sharing options...
robcrozier Posted January 7, 2007 Author Share Posted January 7, 2007 brilliant, thanks guys - ill try both of these strait away and post my results!Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/#findComment-155198 Share on other sites More sharing options...
robcrozier Posted January 7, 2007 Author Share Posted January 7, 2007 worked brilliantly, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/#findComment-155320 Share on other sites More sharing options...
magic2goodil Posted January 7, 2007 Share Posted January 7, 2007 :) click on solved at the bottom left Quote Link to comment https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/#findComment-155321 Share on other sites More sharing options...
HoTDaWg Posted January 7, 2007 Share Posted January 7, 2007 [quote author=magic2goodil link=topic=121408.msg499276#msg499276 date=1168211181]:) click on solved at the bottom left [/quote]i agree.HoTDaWgi gotta stop doing that... Quote Link to comment https://forums.phpfreaks.com/topic/33243-php-domain-name-lookup/#findComment-155323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.