htmlstig Posted March 12, 2009 Share Posted March 12, 2009 hi all i found this script on the net that will check if a domain name exists or not by checking the domains IP <? $hostname = "htmlstig.com"; $hosts = gethostbynamel($hostname); if (is_array($hosts)) { echo "Host ".$hostname." resolves to:<br><br>"; foreach ($hosts as $ip) { echo "IP: ".$ip."<br>"; } } else { echo "Host ".$hostname." is not tied to any IP."; } ?> but i want to check subdomains of htmlstig.com instead so i modified it to <form action="<?php echo $PHP_SELF; ?>" method="post"> <input name="sub" type="text">.htmlstig.com<br> <input name="" type="submit"> </form> <? $hostname = "".$_POST['sub'].".htmlstig.com"; $hosts = gethostbynamel($hostname); if (is_array($hosts)) { echo "Host ".$hostname." resolves to:<br><br>"; foreach ($hosts as $ip) { echo "IP: ".$ip."<br>"; } } elseif ($hostname == ".htmlstig.com"){ echo "Enter Sub-Domain To Check"; } else { echo "Host ".$hostname." is not tied to any IP."; } ?> but i found that if the subdomain doesnt exist instead of returning a blank ip it returns 2 ips and if it does exist it returns 1 ip. now i have figured that out i want to modify it so that if it returns 2 ips it displays a messige and if it returns 1 ip it returns a different message. I presume i would use count() but dont know how to implement it. the script so far can be seen at http://htmlstig.com/availability.php hope someone can help. Cheers **EDIT** sorry i forgot to mention that for testing purposes support.htmlstig.com is a valid subdomain Link to comment https://forums.phpfreaks.com/topic/149033-solved-sub-domain-availability-script-trouble-modifying/ Share on other sites More sharing options...
htmlstig Posted March 12, 2009 Author Share Posted March 12, 2009 not to worry iv figured it out i changed it to <form action="<?php echo $PHP_SELF; ?>" method="post"> <input name="sub" type="text">.htmlstig.com<br> <input name="" type="submit"> </form> <? $hostname = "".$_POST['sub'].".htmlstig.com"; $hosts = gethostbynamel($hostname); if (is_array($hosts)) { if (count($hosts) == 1){ echo "Sub Domain Taken"; } elseif (count($hosts) > 1){ echo "Sub Domain Available"; } } ?> thanks anyway Link to comment https://forums.phpfreaks.com/topic/149033-solved-sub-domain-availability-script-trouble-modifying/#findComment-782619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.