Dynadot โ€” .com Registration $8.99

Whois script...

Spacemail by SpaceshipSpacemail by Spaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
I want to be able to tell my user if a domain is available, and then if it isn't, look it up in a whois database.

I have a substancial list of whois databases, and a whois lookup script, but I just have no way of telling whether a domain is available or registered.

Here is my code already:

PHP:
function get_whois($server,$domain,&$output)
  {
      $whois = fsockopen($server, 43);
      fputs($whois, "$domain\r\n");
      $result = "";
      while(!feof($whois))
      {
          $str = fgets($whois, 1024);
          $result .= $str;
          if (strstr($str, "Whois Server:"))
          {
              $new_server = split(": ", $str);
              $output = chop("$new_server[1]");
              fclose($whois);
              return(1);
          }
      }
      $output = $result;
      fclose($whois);
      return(0);
  }

  include "includes/tlds.php";
  if(!isset($_GET['tld'])){
    $_GET['tld'] = "com";
  }
  if(isset($tlds[$_GET['tld']])){
    $server = $tlds[$_GET['tld']];
  }
  else{
    $server = $tlds["other"];
  }

  $output = "";
  $Domain = $_GET['q'].".".$_GET['tld'];
  // look up a domain name at rs.internic.net
  $redirect = get_whois($server, $Domain, $output);

  // if rs.internic.net doesn't have the information, $output will give us the
  // server that does, so use it to get the registration info
  while ($redirect)
  {
      $whois_server = $output;
      $redirect = get_whois($whois_server, $Domain, $output);
  }

  // ouput the domain registration information
  $echo = nl2br($output);
all the whois servers are stored in an external file in an array called "$tlds['xxx']" (eg: $tlds["co.uk"])

Thanks a lot
Tom
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PHP:
function checkdomain($xserver, $xdomain) {
$sock = fsockopen($xserver,43) or die("Error Connecting To Whois Server");
fputs($sock,"$xdomain\r\n");
while(!feof($sock))
  $result .= fgets($sock,128);
fclose($sock);
if(eregi("No match",$result)||eregi("NOT FOUND",$result))
  return true;
else
  return false;
}
 
0
•••
Jim_ said:
PHP:
if(eregi("No match",$result)||eregi("NOT FOUND",$result))
  return true;
else
  return false;
}
is that what tells me if it is available or not?

If it returns "true" is it available?
 
0
•••
true = available
false = taken
 
0
•••
hmm... sure it works... but it won't connect to the server...:

this is the script I have:
PHP:
function checkdomain($xserver, $xdomain) {
    $got_server = false;
    while(!$got_server){ // while we haven't got a suitable server...
      $result = ""; // empty the $result var
      $sock = fsockopen($xserver,43) or die("Error Connecting To Whois Server"); // connect to server

      fputs($sock,"$xdomain\r\n");

      while(!feof($sock)){
        $result .= fgets($sock,128);
      }

      fclose($sock);

      if (strstr($result, "Whois Server:")){
        $new_server = split(": ", $result);
        $xserver = chop("$new_server[1]");
      }
      else{
        $got_server = true;
      }
    }
    
    if(eregi("No match",$result)||eregi("NOT FOUND",$result)){
      return true;
    }
    else{
      return false;
    }
  }

  include "includes/tlds.php";

  //lets explode the domain...
  $newq = $q.".end";
  $bits = explode(".",$newq);
  $w = count($bits);

  if($w == 4){
    // we have 4 bits in the domain
    // domain.xx.xx.end
    // therefore:
    $thetld = $bits['1'].".".$bits['2']; // eg: co.uk (domain = 0, co = 1, uk = 2, end = 3)
  }
  elseif($w == 3){
    // we have 3 bits in the domain
    // domain.xxx.end
    // therefore:
    $thetld = $bits['1']; // eg: com (domain = 0, com = 1, end = 2)
  }
  else{
    // there must be something wrong...
    $echo = "<font color=\"red\"><b><u>ERROR</u><br />Your domain lookup needs to be in the form \"domain.tld\" <small>eg: 6yd.net</small>.</b></font>";
  }

  if(isset($thetld)){
    $done = checkdomain($tlds[$thetld],$q);
    if($done){
      $echo = "$q is <font color=\"green\"><b>available!</b></font>";
    }
    else{
      $echo = "$q is <font color=\"red\"><b>unavailable, sorry!</b></font>";
      $echo .= nl2br($result);
    }
  }

this is the result I get:
http://beta.6yd.net/yahoo/search.php?q=househuntuk.com&m=domains

change "q" in the query string. Anything taken, and it won't connect... anything available and it will! :( why do you think that is?
 
0
•••
I think its because of your while loop. I don't think its neccessary, so get rid of it. :P
 
0
•••
but that shouldn't be what is stopping it from working. It basically keeps looping incase the server redirects the script to another server. I am sure it is not necessary, but then again, I don't see what is wrong with it.
 
0
•••
I took a look at it and this is the problem:
$new_server = split(": ", $result);
$xserver = chop("$new_server[1]");
you'd need to split $result into each line and then split from the line containing whois server:. It shouldn't matter if it tells you to use a different whois server anyway because that means the domain is registered. Its unneccessary.
 
0
•••
Jim_ said:
It shouldn't matter if it tells you to use a different whois server anyway because that means the domain is registered. Its unneccessary.
yea, but if the domain is registered, I wanted to tell the user the whois info

well... I took out the loop, and it works! :) Thanks a lot!!!

erm... just one more thing, how do I stop it doing this: http://beta.6yd.net/yahoo/search.php?q=google.com&m=domains ???

Thanks
 
0
•••
no-body know how to stop it saying this and just displaying the normal whois record?
Whois Server Version 2.0

Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.


GOOGLE.COM.VN
GOOGLE.COM.UA
GOOGLE.COM.SUCKS.FIND.CRACKZ.WITH.SEARCH.GULLI.COM
GOOGLE.COM.MX
GOOGLE.COM.IS.POWERED.BY.MIKLEFEDOROV.COM
GOOGLE.COM.IS.NOT.HOSTED.BY.ACTIVEDOMAINDNS.NET
GOOGLE.COM.IS.APPROVED.BY.NUMEA.COM
GOOGLE.COM.HAS.LESS.FREE.PORN.IN.ITS.SEARCH.ENGINE.THAN.SECZY.COM
GOOGLE.COM.BR
GOOGLE.COM.AU
GOOGLE.COM
To single out one record, look it up with "xxx", where xxx is one of the
of the records displayed above. If the records are the same, look them up
with "=xxx" to receive a full display for each record.
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back