verifica disponibilità dominio

amhal

Utente Attivo
17 Feb 2011
89
1
8
Ciao a tutti vorrei verificare dal mio sito la disponibilità di un dominio internet ovvero se è già utitlizzato oppure è libero..ho scricato diversi script whois ma nn funzionano e nn capisco perchè...posto quello che sto usando ora, se ne avete uno funzionante postateloooo grazie

pagina index.php

Codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<head>
</head>
<body>
<form method="post" action="examples_domain.php">
Inserisci il nome di dominio: 
<input type="text" name="dominio" size="40">

<br />

  <input type="submit" value="invio">  <input type="reset" value="cancella">
  
</form>

</body>
</html>


pagina examples_domain.php

PHP:
<?php

require("domain.class.php");

// Initializing class
$domain=new domain();

// Printing out whois data
echo $domain->info()."<br>";

// Printing out whois data in HTML format
echo $domain->html_info()."<br><br>";

// Checking if domain is available
if($domain->is_available()){
    echo "Dominio nn disponibile<br>";
}else{
    echo "Dominio Disponibile<br>";
}

// Printing out whois host of domain
echo "Whois Server: ".$domain->get_whois_server()."<br>";

// Printing out name of domain without tld
echo "Domain: ".$domain->get_domain()."<br>";

// Printing out tld name of domain
echo "Tld: ".$domain->get_tld()."<br>";

// Checking if domain name is valid
if($domain->is_valid()){
    echo "dominio valido!<br>";
}else{
    echo "dominio nn valido!<br>";
}

// Getting all suppoerted TLD's
$tlds=$domain->get_tlds();
for($i=0;$i<count($tlds);$i++){
	echo $tlds[$i]."<br>";
}


?>


pagina domain.class.php

PHP:
<?php
/**
* This class checks the availability of a domain and gets the whois data
*
* @author    Sven Wagener <wagener_at_indot_dot_de>
* @copyright inDot media
* @include 	 Funktion:_include_
*/

class domain{
	var $domain="";
	
	/*******************************
	* Initializing server variables
	* array(top level domain,whois_Server,not_found_string or MAX number of CHARS: MAXCHARS:n)
	**/
	var $servers=array(
	
	array("com","whois.crsnic.net","No match"),
		
        array("eu","whois.eu","Status:      FREE"),

	array("it","whois.nic.it","No entries found"),
	
	array("net","whois.crsnic.net","No match"),
	
	array("org","whois.pir.org","NOT FOUND")
		
	);
	
	
	
	var $idn=array(224,225,226,227,228,229,230,231,232,233,234,235,240,236,237,238,239,241,242,243,244,245,246,248,254,249,250,251,252,253,255);
	//	var $idn=array("00E0","00E1","00E2","00E3","00E4","00E5","0101","0103","0105","00E6","00E7","0107","0109","010B","010D","010F","0111","00E8","00E9","00EA","00EB","0113","0115","0117","0119","011B","014B","00F0","011D","011F","0121","0123","0125","0127","00EC","00ED","00EE","00EF","0129","012B","012D","012F","0131","0135","0137","0138","013A","013C","013E","0142","00F1","0144","0146","0148","00F2","00F3","00F4","00F5","00F6","00F8","014D","014F","0151","0153","0155","0157","0159","015B","015D","015F","0161","0163","0165","0167","00FE","00F9","00FA","00FB","00FC","0169","016B","016D","016F","0171","0173","0175","00FD","00FF","0177","017A","017C","017E");
	
	/**
	* Constructor of class domain
	* @param string	$str_domainame    the full name of the domain
	* @desc Constructor of class domain
	*/
	function domain($str_domainname){
		$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");
				
				// New IDN
				if($tldname=="de") {
					fputs($fp, "-C ISO-8859-1 -T dn $dom\r\n");
				} else {
					fputs($fp, "$dom\r\n");
				}
				
				// Getting string
				$string="";
				
				// Checking whois server for .com and .net
				if($tldname=="com" || $tldname=="net" || $tldname=="edu"){
					while(!feof($fp)){
						$line=trim(fgets($fp,128));
						
						$string.=$line;
						
						$lineArr=explode(":",$line);
						
						if(strtolower($lineArr[0])=="whois server"){
							$whois_server=trim($lineArr[1]);
						}
					}
					// 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);
					}
					
					// Checking for other tld's
				}else{
					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= explode("\.",$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 all tlds which are supported by the class
	* @return array $tlds all tlds as array
	* @desc Returns all tlds which are supported by the class
	*/
	function get_tlds(){
		$tlds="";
		for($i=0;$i<count($this->servers);$i++){
			$tlds[$i]=$this->servers[$i][0];
		}
		return $tlds;
	}
	
	/**
	* 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= explode("\.",$this->domain);
		return $domain[0];
	}

	/**
	* Returns the full domain
	* @return string $fulldomain
	* @desc Returns the full domain
	*/
	function get_fulldomain(){
		return $this->domain;
	}
	
	/**
	* 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(); // Gets the entire WHOIS query from registrar
		$not_found_string=$this->get_notfound_string(); // Gets 3rd item from array
		$domain=$this->domain; // Gets current domain being queried
		
		$whois_string2= @preg_replace("$domain","",$whois_string);
		
		$whois_string = @preg_replace("/\s+/"," ",$whois_string); //Replace whitespace with single space
		
		$array=  explode(":",$not_found_string);
		
		if($array[0]=="MAXCHARS"){
			if(strlen($whois_string2)<=$array[1]){
				return true;
			}else{
				return false;
			}
		}else{
			if(preg_match("/".$not_found_string."/i",$whois_string)){
				return true;
			}else{
				return false;
			}
		}
	}
	
	function get_cn_server($whois_text){
		
	}
	
	
	/**
	* 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(){
		
		$domainArr=explode("\.",$this->domain);
		
		// If it's a tld with two Strings (like co.uk)
		if(count($domainArr)==3){
			
			$tld=$domainArr[1].".".$domainArr[2];
			$found=false;
			
			for($i=0;$i<count($this->servers) && $found==false;$i++){
				if($this->servers[$i][0]==$tld){
					$found=true;
				}
			}
			if(!$found){
				return false;
			}
			
		}else if(count($domainArr)>3){
			return false;
		}
		
		// Creating regular expression for
		if($this->get_tld()=="de"){
			for($i=0;$i<count($this->idn);$i++){
				$idn.=chr($this->idn[$i]);
				// $idn.="\x".$this->idn[$i]."";
			}
			$pattern="^[a-z".$idn."0-9\-]{3,}$";
		}else{
			$pattern="^[a-z0-9\-]{3,}$";
		}
		
		if(explode($pattern,strtolower($this->get_domain())) && !preg_match("-|-$",strtolower($this->get_domain())) && !preg_match("/--/",strtolower($this->get_domain()))){
			return true;
		}else{
			return false;
		}
	}
}
?>
 
Discussioni simili
Autore Titolo Forum Risposte Data
L Wordpress: consiglio plugin per "verifica disponibilità" WordPress 0
L [MySQL] Verifica disponibilità camera MySQL 32
M Cosa ne pensate del mio primo file PHP (verifica disponibilità stanze)? PHP 0
C Asp - modulo di prenotazione con verifica disponibilità Classic ASP 12
E Verifica dell'Età Javascript 0
MarcoGrazia Verifica di una stringa o di un nome proveniente da form Snippet PHP 0
G Problema verifica palindromo e verifica pari e dispari javascript Javascript 0
D verifica codice fiscale persona fisica /aziendale stesso campo HTML e CSS 1
F [PHP] Verifica utente presente nel DB PHP 13
gandalf1959 [PHP] Verifica password per accesso ad area riservata PHP 3
M [Javascript] Verifica calcolo prima di fare insert Javascript 13
Samuele Ronzani [PHP] Verifica se un dato esiste già PHP 1
S [Javascript] Verifica separatore decimale sistema operativo Javascript 2
felino EXCEL: verifica dati mancanti tra due sheet Windows e Software 2
A Verifica validità data in Java Java 2
kikki882 verifica account - dati personali Social Media Marketing 0
S [PHP] Verifica dati tramite form e annullamento codice inserito PHP 7
MarcoGrazia Verifica di un indirizzo email Snippet PHP 0
MarcoGrazia [PHP] Verifica dell'input utente tramite funzione generica. PHP 0
francesco87 [Vendo] Verifica pagina (bollino grigio) Annunci servizi di Social Media Marketing 0
M [PHP] Verifica formato data in tempo reale PHP 2
WebDr [Javascript] verifica input Javascript 8
R [WordPress] Accesso al db e verifica credenziali (password criptata) WordPress 1
A VENDO ACCOUNT DI DIVERSE PIATTAFORME E VERIFICA FACEBOOK ACCOUNT(PHOTO TAG VERIFICATION,VERIFICA TEL Annunci servizi di Social Media Marketing 2
P verifica caratteri per email e password PHP 17
S Verifica Esistenza Codice Fiscale PHP 5
C verifica e invio ordine php PHP 19
MarcoGrazia Verifica della data inserita in un form ( utilizzando bootstrap ) Javascript 7
G verifica caricamento foto originali su social network o sito di hosting immagini Discussioni Varie 3
A Strumenti "ufficiali" per la verifica dei Cookie HTML e CSS 2
A verifica di proprietà bing webmaster tool Google Search Console 0
P Verifica form solo con php senza javascript PHP 15
D Verifica inserimento dati form PHP 12
P verifica utente in db PHP 6
L vendo account facebook femmina 5.000 amici con verifica cell e tag superati Annunci servizi di Social Media Marketing 0
V verifica form jQuery 5
filippino Verifica email per attribuzione dei contenuti SEO e Posizionamento 0
N Verifica email di registrazione PHP 0
D Verifica plug-in aggiornati di Firefox non vede gli aggiornamenti effettivi Windows e Software 0
il_bauscia Verifica segnale operatore 5ghz Reti LAN e Wireless 2
Virginia86 [risolto] Problema select e verifica form PHP 38
G php asincrono con ajax 2 campi di verifica PHP 1
P Problema ocon verifica campo in javascript Javascript 7
M adsmanager e messaggio di verifica email Joomla 0
L verifica mail in db con jquery e ajax. Aiuto jQuery 9
asevenx modulo registrazione utenti, cicli if di verifica PHP 9
A Espressione Regolare per verifica stringa PHP 14
A verifica codice PHP 7
M Verifica HTTP o HTTPS PHP 1
M Verifica se una Funzione appartiene ad una Classe PHP 9

Discussioni simili