ciao!
questo è il codice nella pagina web.
Devi includere:
include ("whoisClasses.php");
include("server_list.php");
che ti passo successivamente.
Codice PHP:
<h1>Controlla il dominio</h1>
<form action="http://business.bassanonet.it/hosting/domini.phtml" method="post" id="formDominio" name="formDominio">
<table style="width:200px">
<tr>
<td>[b][url]www.[/url][/b]</td>
<td><input type="text" name="domain" size="24" maxlength="63" value="<?php echo (isset($_POST['domain'])) ? $_POST['domain'] : ""; ?>" /></td>
<td><? create_tld_select(); ?></td>
<td>[url="javascript:document.formDominio.submit()"][img]http://business.bassanonet.it/img/button/vai.gif[/img][/url]</td>
</tr></table>
</form>
<? if($_POST['domain']){ ?>
<?php
if(!$resultObj = $tldList[ $tld ]->checkDomain($domain, $tld)){
if(!$domain){ echo ('<span class="error">È necessario digitare un nome dominio</span>'); }else{
echo('<span class="error">Il dominio scelto presenta caratteri non validi</span>'); }
}
elseif( $resultObj->isAvailable() ){
echo('[b]'.$resultObj->getDomain().'[/b] <span class="true">è disponibile</span>') ;
}else{
echo('[b]'.$resultObj->getDomain().'[/b] <span class="false">non è disponibile</span>') ;
echo(" [url='#'](scopri a chi è stato assegnato)[/url]") ;
}
}
?>
Questa invece è la classe:
Codice PHP:
<?php
/**
* Classe per la gestione degli errori
*/
class ErrorHandler {
var $errors ;
var $TCP_CANNOT_CONNECT ;
var $TCP_CANNOT_SEND ;
var $TCP_CANNOT_READ ;
var $TCP_CANNOT_DISCONNECT ;
var $DOMAIN_NOT_VALID ;
function ErrorHandler()
{
/**
* Un messaggio per ogni tipo di errore che intendiamo intercettare
*/
$this->TCP_CANNOT_CONNECT = 'Impossibile connettersi a ' ;
$this->TCP_CANNOT_SEND = 'Impossibile inviare la seguente request: ' ;
$this->TCP_CANNOT_READ = 'Impossibile lettura da ' ;
$this->TCP_CANNOT_DISCONNECT = 'Impossibile chiudere la connessione a ' ;
$this->DOMAIN_NOT_VALID = 'Nome dominio non valido: ' ;
$this->errors = array() ;
}
/**
* Aggiunge l'errore alla lista
*/
function addError($msg)
{
$this->errors[] = $msg ;
}
/**
* Recupera la lista degli errori
*/
function getErrors()
{
$errorList = '' ;
foreach($this->errors as $v) {
$errorList .= $v . "\n" ;
}
return($errorList) ;
}
} //END class ErrorHandler
/**
* La classe principale:
*connesssione, query e lettura dei risultati da un WHOIS
*/
class WHOISdb extends ErrorHandler {
var $target ;
var $port ;
var $link ;
var $timeout ;
var $crlf ;
var $notFound ;
var $info ;
/**
* Costruttore
*/
function WHOISdb($target, $notFoundMsg, $port = 43, $timeout = 30, $br = "\r\n")
{
$this->ErrorHandler() ;
$this->target = $target ;
$this->port = $port ;
$this->timeout = $timeout ;
$this->crlf = $br ;
$this->notFound = $notFoundMsg ;
$this->info = '' ;
} //END contructor
/**
* Metodo privato per la connessione
*/
function _connect()
{
if (!$this->link = fsockopen($this->target, $this->port, $errno, $errstr, $this->timeout)) {
$this->addError($this->TCP_CANNOT_CONNECT . $this->target . ':' . $this->port) ;
return(false) ;
}
return(true) ;
} //END _connect
/**
* Metodo privato per invio di una request
*/
function _send($domainStr)
{
if (!fputs($this->link, $domainStr . $this->crlf)) {
$this->addError($this->TCP_CANNOT_SEND . $domain . '.' . $tld) ;
return(false) ;
}
return(true) ;
} //END _send
/**
* Metodo privato per la cattura del response
*/
function _get()
{
$dati = '' ;
/**
* Stabilisce il tempo di attesa max prima
* dell'inizio della lettura dei dati
*/
if (function_exists('stream_set_timeout')) {
stream_set_timeout($this->link, $this->timeout, 0);
} while (!feof($this->link) && $line = fgets ($this->link, 4096)) {
if ($line === false || $line === 0) {
$this->addError($this->TCP_CANNOT_READ . $this->target) ;
return(false) ;
}
$dati .= $line ;
}
return($dati) ;
} //END _get
/**
* Metodo principale (pubblico), Ë il metodo che
* controlla la disponibilit‡ del dominio,
* verificando la presenza della stringa $this->notFound.
* Crea l'oggetto WHOISresult
*/
function checkDomain($domain, $tld)
{
$pattern = '<^[0-9A-Za-z]([0-9A-Za-z]|-)+[0-9A-Za-z]\.[A-Za-z]{2,4}(\.[A-Za-z]{2,4})?$>' ;
$domainStr = $domain . '.' . $tld ;
/**
* Verifica la validit‡ dei caratteri del dominio
*/
if (!preg_match($pattern, $domainStr)) {
$this->addError($this->DOMAIN_NOT_VALID . $domainStr) ;
return(false) ;
} elseif (!$this->_connect()) {
return(false) ;
} elseif (!$this->_send($domainStr)) {
return(false) ;
} elseif (!$this->info = $this->_get()) {
return(false) ;
}
$disponibile = (bool)stristr($this->info, $this->notFound) ;
return(new WHOISresult($domainStr, $disponibile, $this->info)) ;
}
} //END class WHOISdb
/**
* Classe da cui si istanziano gli oggetti
* risultato delle query
*/
class WHOISresult {
/**
* Costruttore
*/
function WHOISresult($domain, $disponibile, &$info)
{
$this->domain = $domain ;
$this->disponibile = $disponibile ;
$this->info = &$info ;
}
/**
* Dice se il domain Ë disponibile oppure no
*/
function isAvailable()
{
return($this->disponibile) ;
}
/**
* Restituisce il nome del dominio richiesto
*/
function getDomain()
{
return($this->domain) ;
}
/**
* Restituisce la risposta completa del servizio WHOIS
*/
function getInfo()
{
return($this->info) ;
}
} //END class WHOISresult
?>
Questa la lista che ti dicevo:
Codice PHP:
<?php
/*
Definiamo alcuni oggetti WHOISdb precisando per ognuno il server e la stringa che indica la disponibilit˝ del dominio.
Aggiungi gli altri che ti interessano.
*/
$itnicObj = new WHOISdb('whois.nic.it', 'no entries found') ;
$internicObj = new WHOISdb('whois.internic.net', 'no match for') ;
$euObj = new WHOISdb('whois.eu', 'FREE') ;
$orgObj = new WHOISdb('whois.publicinterestregistry.net', 'not found') ;
$bizObj = new WHOISdb('whois.nic.biz', 'not found') ;
$nameObj = new WHOISdb('whois.nic.name', 'no match') ;
$infoObj = new WHOISdb('whois.afilias.net', 'not found') ;
$deObj = new WHOISdb('whois.denic.de', 'not found') ;
$nlObj = new WHOISdb('whois.domain-registry.nl', 'is free') ;
/*
Array che associa i TLD al corretto WHOIS database
*/
$tldList = array(
'it' => $itnicObj,
'com' => $internicObj,
'eu' => $euObj,
'net' => $internicObj,
'org' => $orgObj,
'biz' => $bizObj,
'name' => $nameObj,
'info' => $infoObj,
'de' => $deObj,
'nl' => $nlObj
);
?>
<?php
function create_tld_select() {
global $tld;
?>
<select name="tld" style="width:50px">
<option value="it" <?php if($tld=="it"){ echo "selected"; } ?>>.it</option>
<option value="com" <?php if($tld=="com"){ echo "selected"; } ?>>.com</option>
<option value="eu" <?php if($tld=="eu"){ echo "selected"; } ?>>.eu</option>
<option value="net" <?php if($tld=="net"){ echo "selected"; } ?>>.net</option>
<option value="org" <?php if($tld=="org"){ echo "selected"; } ?>>.org</option>
<option value="biz" <?php if($tld=="biz"){ echo "selected"; } ?>>.biz</option>
<option value="name" <?php if($tld=="name"){ echo "selected"; } ?>>.name</option>
<option value="info" <?php if($tld=="info"){ echo "selected"; } ?>>.info</option>
<option value="de" <?php if($tld=="de"){ echo "selected"; } ?>>.de</option>
<option value="nl" <?php if($tld=="nl"){ echo "selected"; } ?>>.nl</option>
</select>
<?php
}
?>