Jump to content

[SOLVED] sub domain availability script trouble modifying


htmlstig

Recommended Posts

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

 

 

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

 

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.