Hi all,
still working on my whois class but I'm not getting the expected results from the tiny wee bit of code I'm testing at the moment. If anyone can help I will be eternally grateful.
I put in the following code and then I get the extension listed as the last three parts of anything I put in ('one.two.three.four', extension will be listed as 'two.three.four', name will be 'one'). The point is that the code is supposed to look in the domaintype table of my database and then if a matching 3-part extension exists separate the name and parts accordingly and if not then shunt over one part of the extension to the name part and try for a match on a 2-level extension, and then a one level extension. For instance, input 'blah.com', it looks through the domaintype table, there is no 'blah.com' listed as an extension so 'blah' becomes the name and it searches for a 'com' extension, com exists in the table so we can then extract certain information from the database about the .com registry (or whatever).
<?php
class WhoisClass {
var $DB = 0;
var $wholedomain = ""; //name.extn
var $name = "";
var $extn = "";
var $errArray = array ();
var $errstr = "";
var $whois = "";
var $whoisport = "";
var $whoisip = "";
var $whoisrecurse = "N";
var $validpattern = "";
var $availablepattern = "";
var $extnhandler = "";
var $BUFFER = 0; //read buffer char by char
var $rawwhoisArray = array();
var $resultArray = array();
// constructor
function WhoisClass($newDB, $domainName) {
$this->DB = $newDB;
$this->wholedomain = strtolower(preg_replace("/[\n\s]/", "", $domainName));
$domparts = explode('.', $this->wholedomain);
$last = array_pop($domparts);
$negOne = array_pop($domparts);
$negTwo = array_pop($domparts); //to cope with 3-level tlds
$this->name = implode ('.', $domparts);
// for 3-level
$this->extn = $negTwo.'.'.$negOne.'.'.$last;
//see if can find a matching 3-level extension in the db
$extnMatched = $this->match_extn($this->extn);
if ($extnMatched = TRUE) {
//proceed with whois
} else {
//we push the 'first extension bit' from the extension onto the name to create a 2-level extn
$domparts = array_push($domparts, $negTwo);
$this->name = implode('.', $wholedomain);
$this->extn = $negOne.'.'.$last;
}//end 2-level match
}//end constructor
function match_extn($extn){
$match_result = $this->DB->query("SELECT * FROM domaintype WHERE suffix = '$this->extn'");
if(!empty ($match_result)) {
//take out what we need from the domaintype table by item name
//$myrow = mysql_fetch_array($match_result)
//$myrow["whois"] = $this->whois;
$this->extnMatched = TRUE;
return $this->extnMatched;
} else {
$this->extnMatched = FALSE;
return $this->extnMatched;
}//end else
}//end function
}//end class
?>