Jump to content

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

 

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.