check domain name availability
“domaincheck” makes use of the built-in PHP functions
nl2br( ),
count( ),
intval( ),
strlen( ),
substr( ),
fsockopen( ),
fputs( ),
feof( ),
fgets( ),
fclose( ),
preg_match_all( ) and
ereg( ).
001 <?php
002
003 echo '
004 <form name="form1" method="post" action="./">
005 <b>Domain (without www.):</b>
006 <input type="text" name="dom" />
007 <select name="endung">
008 <option value=".de">.de</option>
009 <option value=".com">.com</option>
010 <option value=".net">.net</option>
011 <option value=".org">.org</option>
012 <option value=".info">.info</option>
013 <option value=".biz">.biz</option>
014 <option value=".at">.at</option>
015 <option value=".ch">.ch</option>
016 <option value=".li">.li</option>
017 <option value=".co.uk">.co.uk</option>
018 <option value=".tv">.tv</option>
019 <option value=".cc">.cc</option>
020 <option value=".dk">.dk</option>
021 <option value=".it">.it</option>
022 <option value=".ws">.ws</option>
023 </select>
024 <input type="submit" name="Submit" value="Check" />
025 </form>';
026
027 if (isset($_POST['dom']))
028 {
029 $dom = $_POST['dom'].$_POST['endung'];
030 $whoisresult = lookup($dom);
031 echo '
032 <p style="padding: 0.8em;">
033 '.nl2br($whoisresult).'
034 </p>';
035 }
036
037 function get_whois_server($domain)
038 {
039 $whoisservers = array(array('de','whois.denic.de'),
040 array('com','rs.internic.net'),
041 array('net','rs.internic.net'),
042 array('org','whois.networksolutions.com'),
043 array('info','whois.afilias.net'),
044 array('biz','whois.biz'),
045 array('at','whois.nic.at'),
046 array('ch','whois.nic.ch'),
047 array('li','whois.nic.ch'),
048 array('co.uk','whois.nic.uk'),
049 array('tv','whois.<a href = "http://www.tv" target = "_blank">www.tv</a>'),
050 array('cc','whois.enicregistrar.com'),
051 array('dk','whois.dk-hostmaster.dk'),
052 array('it','whois.nic.it'),
053 array('ws','whois.worldsite.ws'));
054 $whocnt = count($whoisservers);
055 for ($x = 0;$x<$whocnt;$x++)
056 {
057 $artld = $whoisservers[$x][0];
058 $tldlen = intval(0 - strlen($artld));
059 if (substr($domain, $tldlen) == $artld) $whosrv = $whoisservers[$x][1];
060 }
061 return $whosrv;
062 }
063
064 function lookup($dom)
065 {
066 $lusrv = get_whois_server($dom);
067 if (!$lusrv) return '';
068 $fp = fsockopen($lusrv,43);
069 fputs($fp,$dom."\r\n");
070 $string = '';
071 while(!feof($fp)) $string .= fgets($fp,128);
072 fclose($fp);
073 $reg = "/Whois Server: (.*?)\n/i";
074 preg_match_all($reg, $string, $matches);
075 if(isset($matches[1][0])) $secondtry = $matches[1][0];
076 if(isset($secondtry))
077 {
078 $fp = fsockopen($secondtry,43);
079 fputs($fp, $dom."\r\n");
080 $string = '';
081 while(!feof($fp)) $string .= fgets($fp,128);
082 fclose($fp);
083 }
084 if(ereg('(No match|No entries found|NOT FOUND|Not found)',$string))
085 {
086 echo '
087 <p>
088 <b>the search for '.$dom.' returned nothing</b>
089 </p>';
090 }else{
091 echo '
092 <p>
093 <b>the search for '.$dom.' returned following:</b>
094 </p>';
095 $whois = $string;
096 return $whois;
097 }
098 }
099
100 ?>