Jump to content

Whois - Tld String


verror

Recommended Posts

I am currently working on/updating a whois script (PHPAjaxwhois)

 

At current you have the ability to enter a domain (without the extension. e.g: www.google) and then select a tld/extension from a list of check boxes before searching. I am working on updating this to not require the selection of a tld/extension via a check box but by just typing it directly in (e.g www.google.com) for the search.

 

The original code is:

 

class AjaxWhois{
   var $serverList;
   var $tr = 0;
function CheckWhois($domain){

 return "
 <a href=\"#\" onclick=\"javascript:makeRequest('get.php', '?domain=$domain');\">Whois</a>
 ";
}
function tldList(){
		 $i = 0;
		    foreach ($this->serverList as $value) {
			    if ($value['check'] == true) $checked=" checked='checked' ";
		  else $checked = " ";

		  echo '<td><input type="checkbox" name="tld_'.$value['tld'].'"'.$checked.' />.'.$value['tld'].'</td>';
			    $i++;			 
		  if ($i > 4) {
			  $i = 0;
			  echo '</tr><tr>';
		  }
		 }

}
function processAjaxWhois(){
    $domainName = (isset($_POST['domain'])) ? $_POST['domain'] : '';

    for ($i = 0; $i < sizeof($this->serverList); $i++) {
	 $actTop = "
_".$this->serverList[$i]['tld'];
  $check = str_replace(".", "_", $actTop);
	 $this->serverList[$i]['check'] = isset($_POST[$check]) ? true : false;
    }
    if (strlen($domainName)>2){
  echo '<fieldset><legend class="green">Whois results</legend>';
	    echo '<table class="tabel">';
	    echo '<tr><th colspan="2"></th></tr>';

	    for ($i = 0; $i < sizeof($this->serverList); $i++) {
	  if ($this->serverList[$i]['check']){
	 $this->showDomainResult($domainName.".".$this->serverList[$i]['tld'],
							 $this->serverList[$i]['server'],
							 $this->serverList[$i]['response']);
   }
  }

  echo '</table></fieldset>';
    }
}
function showDomainResult($domain,$server,$findText){
  if ($this->tr == 0){
   $this->tr = 1;
   $class = " class='alt'";
  } else {
   $this->tr = 0;
   $class = "";
  }
  if ($this->checkDomain($domain,$server,$findText)){
  echo "<tr $class><td><span class='td'>$domain</span></td><td class='disponibil'><img src='images/available.png' width='16' height='16' align='absmiddle'/>  AVAILABLE | <a href='#'>REGISTER DOMAIN NAME</td></a></tr>";
  }
  else echo "<tr $class><td><span class='ta'>$domain</span></td><td class='ocupat'><img src='images/taken.png' width='16' height='16' align='absmiddle'/> 
TAKEN <a href='http://www.$domain/' target='_blank'> WWW </a>  ".$this->CheckWhois($domain)."</td></tr>";
}
function checkDomain($domain,$server,$findText){
$con = fsockopen($server, 43);
if (!$con) return false;
fputs($con, $domain."\r\n");
$response = ' :';
while(!feof($con)) {
$response .= fgets($con,128);
}
fclose($con);
$tld = substr($domain, -3, 3);
//echo $tld;
if ($tld == ".au") {
if (strpos($response, $findText)){
return false;
}
else {
return true;
}
} else {
if (strpos($response, $findText)){
return true;
}
else {
return false;
}
}
}
//whois servers and extensions
function AjaxWhois(){  

$this->serverList[0]['tld']	  = 'com.au';
$this->serverList[0]['server']   = 'whois-check.ausregistry.net.au';
$this->serverList[0]['response'] = 'Not';
$this->serverList[0]['check']    = false;

$this->serverList[1]['tld']	  = 'net.au';
$this->serverList[1]['server']   = 'whois-check.ausregistry.net.au';
$this->serverList[1]['response'] = 'Not';
$this->serverList[1]['check']    = false;
$this->serverList[2]['tld']	  = 'org.au';
$this->serverList[2]['server']   = 'whois-check.ausregistry.net.au';
$this->serverList[2]['response'] = 'Not';
$this->serverList[2]['check']    = false;
$this->serverList[3]['tld']	  = 'asn.au';
$this->serverList[3]['server']   = 'whois-check.ausregistry.net.au';
$this->serverList[3]['response'] = 'Not';
$this->serverList[3]['check']    = false;
$this->serverList[4]['tld']	  = 'id.au';
$this->serverList[4]['server']   = 'whois-check.ausregistry.net.au';
$this->serverList[4]['response'] = 'Not';
$this->serverList[4]['check']    = false;
 $this->serverList[5]['tld']	  = 'com';
$this->serverList[5]['server']   = 'whois.crsnic.net';
$this->serverList[5]['response'] = 'No match for';
$this->serverList[5]['check']    = false;

$this->serverList[6]['tld']	  = 'net';
$this->serverList[6]['server']   = 'whois.crsnic.net';
$this->serverList[6]['response'] = 'No match for';
$this->serverList[6]['check']    = false;
$this->serverList[7]['tld']	  = 'org';
$this->serverList[7]['server']   = 'whois.publicinterestregistry.net';
$this->serverList[7]['response'] = 'NOT FOUND';
$this->serverList[7]['check']    = false;

$this->serverList[8]['tld']	  = 'info';
$this->serverList[8]['server']   = 'whois.afilias.net';
$this->serverList[8]['response'] = 'NOT FOUND';
$this->serverList[8]['check']    = false;

$this->serverList[9]['tld']	  = 'name';
$this->serverList[9]['server']   = 'whois.nic.name';
$this->serverList[9]['response'] = 'No match';
$this->serverList[9]['check']    = false;

$this->serverList[10]['tld']	  = 'us';
$this->serverList[10]['server']   = 'whois.nic.us';
$this->serverList[10]['response'] = 'Not found:';
$this->serverList[10]['check']    = false;
$this->serverList[11]['tld']	  = 'biz';
$this->serverList[11]['server']   = 'whois.nic.biz';
$this->serverList[11]['response'] = 'Not found';
$this->serverList[11]['check']    = false;

$this->serverList[12]['tld']	  = 'ca';
$this->serverList[12]['server']   = 'whois.cira.ca';
$this->serverList[12]['response'] = 'AVAIL';
$this->serverList[12]['check']    = false;
$this->serverList[13]['tld']	  = 'nz';
$this->serverList[13]['server']   = 'whois.srs.net.nz';
$this->serverList[13]['response'] = 'No Data Found';
$this->serverList[13]['check']    = false;
$this->serverList[14]['tld']	  = 'eu';
$this->serverList[14]['server']   = 'whois.eu';
$this->serverList[14]['response'] = 'FREE';
$this->serverList[14]['check']    = false;
$this->serverList[15]['tld']	  = 'ro';
$this->serverList[15]['server']   = 'whois.rotld.ro';
$this->serverList[15]['response'] = 'No entries found for the selected source';
$this->serverList[15]['check']    = false;
$this->serverList[16]['tld']	  = 'ws';
$this->serverList[16]['server']   = 'whois.nic.ws';
$this->serverList[16]['response'] = 'No match for';
$this->serverList[16]['check']    = false;

$this->serverList[17]['tld']	  = 'co.uk';
$this->serverList[17]['server']   = 'whois.nic.uk';
$this->serverList[17]['response'] = 'No match for';
$this->serverList[17]['check']    = false;
$this->serverList[18]['tld']	  = 'de';
$this->serverList[18]['server']   = 'whois.denic.de';
$this->serverList[18]['response'] = 'not found in database';
$this->serverList[18]['check']    = false;

}
}
?>

 

And the form:

 

<form id="whois" action="whois.php" method="post" >
   <div id="domain">
   <fieldset>
   <legend>Search for your domain name</legend>
 <h2 style="margin-left:10px;"></h2>
 <div class="l1">	 
  <span style="font-size:18px;">www.</span><input type="text" name="domain" class="input"/>
  <p align="center" style="font-size:14px;">(e.g yourcompany)</p>
 </div>
   <div class="l2">
 <table width="580" border="0" cellspacing="0" cellpadding="0">
  <tr>
  <?php $whois->tldList();?>
  </tr>
 </table>
  </div>
   <div class="r"><br />
 <input name="Submit" type="submit" value="Search" class="input" /> 
   </div>		  
  </fieldset></div>	  
 </form>
</div>

 

I assume that to accomplish the change I would need to run a query against what has been entered into the text file to grab anything after the first "." and call that as the tld, something like this:

$domaintld = explode(".", $domain);
$tld = strtolower(array_pop($domaintld));

But I am unsure on how to implement this into the code.

 

Any help would be appreciated.

Link to comment
Share on other sites

Since you want to capture the input of a dot (period) on-the-fly / live it is not considered a server side script. In other words.. PHP would have nothing to do with capturing the dot character as they type.

 

Javascript is what you are looking for ... and jQuery is the best possible framework that I know of to implement your Javascript.

 

Here is an example to get you started

http://api.jquery.com/keypress/

Link to comment
Share on other sites

Thanks for the reply Zane.

 

It's not exactly what I am looking for whoever, I more-so require the php script to read what has been entered into the text field after the user hits submit to then grab the domain extension that has been placed so that the script can then run the whois check.

Link to comment
Share on other sites

Thats simple

 

<?php
function get_tld($domain)
{
   $parts  = parse_url($domain);
   if(!isset($parts['path']))
   {
       return FALSE;    
   }
   $domain = $parts['path'];
   return trim(substr($domain, strpos($domain, '.', 0) + 1, strlen($domain)));    
}

echo get_tld('google.com') . '<br />';
echo get_tld('google.co.uk') . '<br />';
echo get_tld('foobar.uk.com') . '<br />';
// this one is bad
echo get_tld('http://www.google.es');
?>

Edited by neil.johnson
Link to comment
Share on other sites

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.