En este post vamos a ver como realizar un script que me permita verificar la disponibilidad de los dominios, echo principalmente con PHP y utilizando un poco de ajax con Json y jQuery.
Crearemos 2 archivos php y 1 css para darle un poco de stylo a nuestro ejemplo, tambien descargaremos la libreria jquery.
index.php
<html> <head> <title>Jquery Easy - Verificar si un dominio esta disponible con php y json</title> <link href="main.css" rel="stylesheet" /> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script language="javascript"> $(document).ready(function() { var loading; var results; var form; form = document.getElementById('form'); loading = document.getElementById('loading'); results = document.getElementById('results'); $('#Submit').click( function() { if($('#Search').val() == "") {alert('Ingrese un dominio');return false;} results.style.display = 'none'; $('#results').html(''); loading.style.display = 'inline'; $.post('process.php?domain=' + escape($('#Search').val()),{ }, function(response){ results.style.display = 'block'; $('#results').html(unescape(response)); loading.style.display = 'none'; }); return false; }); }); </script> </head> <body> <div class="cabecera"><img src="images/logo.gif" /></div> <h3 align="center">Verificar si un dominio esta disponible con php y json</h3> <center> <form method="post" action="./" id="form"> <h3 style="color:#FFF">Ingrese solo el nombre del dominio (*sin prefijo .com, .org, etc)</h3> <input type="text" autocomplete="off" id="Search" name="domain"> <input type="submit" id="Submit" value="Submit"> </form> <div id="loading">Enviando datos....</div> <div id="results" style="width:420px; height:600px;" align="left"> </div> </center> </body> </html></pre> En este archivo estamos diseñando nuestro formulario de consulta y estamos creando un metodo con jquery para validar y enviar los datos de mi formulario por ajax hacia el archivo que va aprocesar los datos. <h5>process.php</h5> <pre class="brush:php"><?php set_time_limit(0); ob_start(); ########### Extensiones $extensions = array( '.com' => array('whois.crsnic.net','No match for'), '.info' => array('whois.afilias.net','NOT FOUND'), '.net' => array('whois.crsnic.net','No match for'), '.co.uk' => array('whois.nic.uk','No match'), '.nl' => array('whois.domain-registry.nl','not a registered domain'), '.ca' => array('whois.cira.ca', 'AVAIL'), '.name' => array('whois.nic.name','No match'), '.ws' => array('whois.website.ws','No Match'), '.be' => array('whois.ripe.net','No entries'), '.org' => array('whois.pir.org','NOT FOUND'), '.biz' => array('whois.biz','Not found'), '.tv' => array('whois.nic.tv', 'No match for'), ); ########### if(isset($_GET['domain'])) { $domain = str_replace(array('www.', 'http://','/'), NULL, $_GET['domain']); if(strlen($domain) > 0) { foreach($extensions as $extension => $who) { $buffer = NULL; $sock = fsockopen($who[0], 43) or die('Error Connecting To Server:' . $server); fputs($sock, $domain.$extension . "\r\n"); while( !feof($sock) ) { $buffer .= fgets($sock,128); } fclose($sock); if(eregi($who[1], $buffer)) { echo '<h4 class="available"><span>Disponible</span>' . $domain. '<b>' . $extension .'</b> Esta Disponible</h4>'; } else { echo '<h4 class="taken"><span>Tomado</span>' . $domain . '<b>' .$extension .'</b> Esta Tomado</h4>'; } echo '<br />'; ob_flush(); flush(); sleep(0.3); } } else { echo 'Por favor ingrese nombre del dominio'; } } ?></pre> Este archivo es el que recibe los parametros y realiza la busqueda del valor ingresado, creando un array con los prefijos de los dominios mas usados y nos devuelve los valores. <h5>main.css</h5> <pre class="brush:css">body { font-family: Tahoma, sans-serif; font-size: 12px; font-weight: bold; } .cabecera { background: #4A3C31; border-bottom: 5px solid #69AD3C; margin: -8px 0 0 -8px; width: 100%; } .cabecera img { margin: 40px 0 0 30px; } #loading { display: none; } #form { width: 520px; background-color: #4A3C31; padding: 40px 50px 30px; margin: 10px 0; position: relative; border-radius: 15px; -moz-border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px 15px 15px 15px; border: solid 5px #69AD3C; } #Search { border: medium none; color: #888888; float: left; font-family: Arial,Helvetica,Sans-serif; font-size: 15px; height: 36px; margin-right: 12px; outline: medium none; padding: 0 0 0 35px; text-shadow: 1px 1px 0 white; width: 425px; } #Submit { background: url("Search.png") no-repeat scroll 0 0 transparent; border: medium none; cursor: pointer; height: 36px; overflow: hidden; text-indent: -999px; text-transform: uppercase; width: 83px; } h4 { border: 2px solid #EEEEEE; font: 14px/1.3 Verdana,"Lucida Grande",Arial,Helvetica,Sans-Serif; margin: 0px; padding: 5px; min-width: 120px; text-align: left } h4.taken span { background: none repeat scroll 0 0 #F08F78; } h4.taken:hover { background: none repeat scroll 0 0 #FFC5B7; } h4 a { font-family:"crete-rounded-web-1","crete-rounded-web-2",sans-serif; color: #333333 } h4 span { font-family: Verdana; font-size: 12px; font-style: normal; margin-right: 4px; padding: 3px 5px; } h4.available:hover { background: none repeat scroll 0 0 #DDF2BC; } h4.available span { background: #bce67b; }
Esto es para darle un poco de vistosidad a nuestro ejercicio, espero que le sirva y cualquier duda pueden comentar.