PHPBuilder - Domain class



RSS Twitter
Snippets Networking

Domain class

by: Sven Wagener
|
August 13, 2002

Version: 1.0

Type: Class

Category: Networking

License: GNU General Public License

Description: This class checks the availability of a domain and gets the whois data. You can check domains of the following tld's: * - ac * - ac.jp * - ac.uk * - ad.jp * - aero * - ag * - al * - at * - au * - as * - asn.au * - be * - bg * - biz * - br * - ca * - cc * - ch * - cl * - cd * - com * - com.au * - com.eg * - com.mx * - com.tw * - conf.au * - co.uk * - csiro.au * - cx * - cz * - de * - dk * - ee * - edu * - edu.au * - eg * - es * - eun.eg * - edu.id.au * - fi * - fo * - fr * - ge * - gl * - gr * - gr.jp * - gs * - gob.mx * - gov.au * - hm * - mc * - mil * - ms * - mx * - name * - ne.jp * - net * - net.au * - net.eg * - net.lu * - net.mx * - net.uk * - net.tw * - nl * - id.au * - ie * - info * - info.au * - it * - idv.tw * - jp * - la * - li * - lk * - lt * - lu * - ltd.uk * - plc.uk * - or.jp * - org * - org.au * - org.lu * - org.tw * - org.uk * - pl * - pt * - ru * - th * - to * - tw * - uk * - wattle.id.au



<?
/**
* This class checks the availability of a domain and gets the whois data
* You can check domains of the following tld's
* (PLEASE CONTACT ME IF A WHOIS SERVER ISN'T RIGHT!)
* - ac
* - ac.jp
* - ac.uk
* - ad.jp
* - aero
* - ag
* - al
* - at
* - au
* - as
* - asn.au
* - be
* - bg
* - biz
* - br
* - ca
* - cc
* - ch
* - cl
* - cd
* - com
* - com.au
* - com.eg
* - com.mx
* - com.tw
* - conf.au
* - co.uk
* - csiro.au
* - cx
* - cz
* - de
* - dk
* - ee
* - edu
* - edu.au
* - eg
* - es
* - eun.eg
* - edu.id.au
* - fi
* - fo
* - fr
* - ge
* - gl
* - gr
* - gr.jp
* - gs
* - gob.mx
* - gov.au
* - hm
* - mc
* - mil
* - ms
* - mx
* - name
* - ne.jp
* - net
* - net.au
* - net.eg
* - net.lu
* - net.mx
* - net.uk
* - net.tw
* - nl
* - id.au
* - ie
* - info
* - info.au
* - it
* - idv.tw
* - jp
* - la
* - li
* - lk
* - lt
* - lu
* - ltd.uk
* - plc.uk
* - or.jp
* - org
* - org.au
* - org.lu
* - org.tw
* - org.uk
* - pl
* - pt
* - ru
* - th
* - to
* - tw
* - uk
* - wattle.id.au
*
* @author    Sven Wagener <sven.wagener@intertribe.de>
* @copyright Intertribe Limited
* @include 	 Funktion:_include_
*/
class domain{
    var $domain="";
    var $servers="";
    
	/**
	* Constructor of class domain
	* @param string	$str_domainame    the full name of the domain
	* @desc Constructor of class domain
	*/
    function domain($str_domainname){
        /*******************************
        * Initializing server variables
        * array(top level domain,whois_Server,not_found_string))
        **/
        $i=0;
        $this->servers[$i++]=array("ac","whois.nic.ac","No match");
        $this->servers[$i++]=array("ac.jp","whois.nic.ad.jp","No match");
        $this->servers[$i++]=array("ac.uk","whois.ja.net","no entries");
        $this->servers[$i++]=array("ad.jp","whois.nic.ad.jp","No match");
        $this->servers[$i++]=array("aero","whois.information.aero","is available");
        $this->servers[$i++]=array("ag","whois.nic.ag","does not exist");
        $this->servers[$i++]=array("al","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("at","whois.nic.at","nothing found");
        $this->servers[$i++]=array("au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("as","whois.nic.as","Domain Not Found");
        $this->servers[$i++]=array("asn.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("be","whois.dns.be","No such domain");
        $this->servers[$i++]=array("bg","whois.digsys.bg","does not exist");
        $this->servers[$i++]=array("biz","whois.biz","Not found");
        $this->servers[$i++]=array("br","whois.registro.br","No match");
        $this->servers[$i++]=array("ca","whois.cira.ca","Status: AVAIL");
        $this->servers[$i++]=array("cc","whois.nic.cc","No match");
        $this->servers[$i++]=array("cd","whois.cd","No match");
        $this->servers[$i++]=array("ch","whois.nic.ch","We do not have an entry");
        $this->servers[$i++]=array("cl","whois.nic.cl","no existe");
        $this->servers[$i++]=array("com","whois.verisign-grs.net","No match");
        $this->servers[$i++]=array("com.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("com.eg","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("com.mx","whois.nic.mx","Nombre del Dominio");
        $this->servers[$i++]=array("com.tw","whois.twnic.net","NO MATCH TIP");
        $this->servers[$i++]=array("conf.au","whois.aunic.net","No entries found");
        $this->servers[$i++]=array("co.jp","whois.nic.ad.jp","No match");
        $this->servers[$i++]=array("co.uk","whois.nic.uk","No match for");
        $this->servers[$i++]=array("csiro.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("cx","whois.nic.cx","No match");
        $this->servers[$i++]=array("cz","whois.nic.cz","No data found");
        $this->servers[$i++]=array("de","whois.denic.de","No entries found");
        $this->servers[$i++]=array("dk","whois.dk-hostmaster.dk","No entries found");
        $this->servers[$i++]=array("ee","whois.eenet.ee","NOT FOUND");
        $this->servers[$i++]=array("edu","whois.verisign-grs.net","No match");
        $this->servers[$i++]=array("edu.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("eg","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("es","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("eun.eg","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("emu.id.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("fi","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("fo","whois.ripe.net","no entries found");
        $this->servers[$i++]=array("fr","whois.nic.fr","No entries found");
        $this->servers[$i++]=array("ge","whois.ripe.net","no entries found");
        $this->servers[$i++]=array("gl","whois.ripe.net","no entries found");
        $this->servers[$i++]=array("gr","whois.ripe.net","no entries found");
        $this->servers[$i++]=array("gr.jp","whois.nic.ad.jp","No match");
        $this->servers[$i++]=array("gov.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("gob.mx","whois.nic.mx","Nombre del Dominio");
        $this->servers[$i++]=array("gs","whois.adamsnames.tc","is not registered");
        $this->servers[$i++]=array("hm","whois.registry.hm","(null)");
        $this->servers[$i++]=array("mc","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("mil","whois.nic.mil","No match");
        $this->servers[$i++]=array("ms","whois.adamsnames.tc","is not registered");
        $this->servers[$i++]=array("mx","whois.nic.mx","Nombre del Dominio");
        $this->servers[$i++]=array("name","whois.nic.name","No match");
        $this->servers[$i++]=array("ne.jp","whois.nic.ad.jp","No match");
        $this->servers[$i++]=array("net","whois.verisign-grs.net","No match");
        $this->servers[$i++]=array("net.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("net.eg","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("net.lu","whois.dns.lu","No entries found");
        $this->servers[$i++]=array("net.mx","whois.nic.mx","Nombre del Dominio");
        $this->servers[$i++]=array("net.uk","whois.nic.uk","No match for ");
        $this->servers[$i++]=array("net.tw","whois.twnic.net","NO MATCH TIP");
        $this->servers[$i++]=array("nl","whois.domain-registry.nl","is not a registered domain");
        $this->servers[$i++]=array("id.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("ie","whois.domainregistry.ie","no match");
        $this->servers[$i++]=array("info","whois.afilias.info","Not found");
        $this->servers[$i++]=array("info.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("it","whois.nic.it","No entries found");
        $this->servers[$i++]=array("idv.tw","whois.twnic.net","NO MATCH TIP");
        $this->servers[$i++]=array("int","whois.iana.org","not found");
        $this->servers[$i++]=array("is","whois.isnic.is","No entries found");
        $this->servers[$i++]=array("jp","whois.nic.ad.jp","No match");
        $this->servers[$i++]=array("la","whois.nic.la","NO MATCH");
        $this->servers[$i++]=array("li","whois.nic.ch","We do not have an entry");
        $this->servers[$i++]=array("lk","whois.nic.lk","No domain registered");
        $this->servers[$i++]=array("lt","ns.litnet.lt","No matches found");
        $this->servers[$i++]=array("lu","whois.dns.lu","No entries found");
        $this->servers[$i++]=array("ltd.uk","whois.nic.uk","No match for");
        $this->servers[$i++]=array("plc.uk","whois.nic.uk","No match for");
        $this->servers[$i++]=array("or.jp","whois.nic.ad.jp","No match");
        $this->servers[$i++]=array("org","whois.verisign-grs.net","No match");
        $this->servers[$i++]=array("org.au","whois.aunic.net","No Data Found");
        $this->servers[$i++]=array("org.lu","whois.dns.lu","No entries found");
        $this->servers[$i++]=array("org.tw","whois.twnic.net","NO MATCH TIP");
        $this->servers[$i++]=array("org.uk","whois.nic.uk","No match for");
        $this->servers[$i++]=array("pl","nazgul.nask.waw.pl","does not exists");
        $this->servers[$i++]=array("pt","whois.ripe.net","No entries found");
        $this->servers[$i++]=array("ru","whois.ripn.ru","No entries found");
        $this->servers[$i++]=array("th","whois.nic.uk","No entries found");
        $this->servers[$i++]=array("to","whois.tonic.to","No match");
        $this->servers[$i++]=array("tw","whois.twnic.net","NO MATCH TIP");
        $this->servers[$i++]=array("uk","whois.thnic.net","No match for");
        $this->servers[$i++]=array("wattle.id.au","whois.aunic.net","No Data Found");

        $this->domain=$str_domainname;
    }

	/**
	* Returns the whois data of the domain
	* @return string $whoisdata Whois data as string
	* @desc Returns the whois data of the domain
	*/
    function info(){
        if($this->is_valid()){

            $tldname=$this->get_tld();
            $domainname=$this->get_domain();
            $whois_server=$this->get_whois_server();
            
            // If tldname have been found
            if($whois_server!=""){
                // Getting whois information
                $fp = fsockopen($whois_server,43);

                $dom=$domainname.".".$tldname;
                fputs($fp, "$dom\r\n");

                // Getting string
                $string="";
                while(!feof($fp)){
                    $string.=fgets($fp,128);
                }
                fclose($fp);
                return $string;
            }else{
                return "No whois server for this tld in list!";
            }
        }else{
            return "Domainname isn't valid!";
        }
    }

	/**
	* Returns the whois data of the domain in HTML format
	* @return string $whoisdata Whois data as string in HTML
	* @desc Returns the whois data of the domain  in HTML format
	*/
    function html_info(){
        return nl2br($this->info());
    }

    /**
	* Returns name of the whois server of the tld
	* @return string $server the whois servers hostname
	* @desc Returns name of the whois server of the tld
	*/
    function get_whois_server(){
            $found=false;
            $tldname=$this->get_tld();
            for($i=0;$i<count($this->servers);$i++){
                if($this->servers[$i][0]==$tldname){
                    $server=$this->servers[$i][1];
                    $full_dom=$this->servers[$i][3];
                    $found=true;
                }
            }
            return $server;
    }

    /**
	* Returns the tld of the domain without domain name
	* @return string $tldname the tlds name without domain name
	* @desc Returns the tld of the domain without domain name
	*/
    function get_tld(){
       // Splitting domainname
       $domain=split("\.",$this->domain);
       if(count($domain)>2){
           $domainname=$domain[0];
           for($i=1;$i<count($domain);$i++){
               if($i==1){
                  $tldname=$domain[$i];
               }else{
                  $tldname.=".".$domain[$i];
               }
            }
       }else{
           $domainname=$domain[0];
           $tldname=$domain[1];
       }
       return $tldname;
    }

    /**
	* Returns the name of the domain without tld
	* @return string $domain the domains name without tld name
	* @desc Returns the name of the domain without tld
	*/
    function get_domain(){
       // Splitting domainname
       $domain=split("\.",$this->domain);
       return $domain[0];
    }

	/**
	* Returns the string which will be returned by the whois server of the tld if a domain is avalable
	* @return string $notfound  the string which will be returned by the whois server of the tld if a domain is avalable
	* @desc Returns the string which will be returned by the whois server of the tld if a domain is avalable
	*/
    function get_notfound_string(){
       $found=false;
       $tldname=$this->get_tld();
       for($i=0;$i<count($this->servers);$i++){
           if($this->servers[$i][0]==$tldname){
               $notfound=$this->servers[$i][2];
           }
       }
       return $notfound;
    }
    
	/**
	* Returns if the domain is available for registering
	* @return boolean $is_available Returns 1 if domain is available and 0 if domain isn't available
	* @desc Returns if the domain is available for registering
	*/
    function is_available(){
        $whois_string=$this->info();
        if(preg_match("/".$this->get_notfound_string()."/i",$whois_string)){
            return true;
        }else{
            return false;
        }
    }

	/**
	* Returns if the domain name is valid
	* @return boolean $is_valid Returns 1 if domain is valid and 0 if domain isn't valid
	* @desc Returns if the domain name is valid
	*/
    function is_valid(){
        if(ereg("^[a-zA-Z0-9\-]{3,}$",$this->get_domain()) && !preg_match("/--/",$this->get_domain())){
            return true;
        }else{
            return false;
        }
    }
}
?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Sven Wagener

Comment:



Comment:

(Maximum characters: 1200). You have characters left.