PHP Forums Archive

PHP Ajax Whois Script

Tags: php, ajax, whois, example code

Olaf posted on 2008-08-20 12:29:33 #

Today we have changed the PHP Whois demo on our website.

We modified the default PHP whois class example script a little bit and used xajax to create a ajax powered request form.

The code for the ajax request (place it above the html code)

$my_whois = new Whois_domain;
$my_whois->possible_tlds = array('com','net','org','info','us','name','biz'); 

function myFunction($get) {
	global $servers;
    $objResponse = new xajaxResponse();
	$my_whois = new Whois_domain;
	$my_whois->tld = $get['tld'];
	$my_whois->domain = $get['domain'];
	if ($my_whois->create_domain()) {
		$my_whois->free_string = $servers[$get['tld']]['free'];
		$my_whois->whois_server = $servers[$get['tld']]['address'];
		$my_whois->whois_param = $servers[$get['tld']]['param'];
		$test = $my_whois->check_only();
		if ($test == 1) {
			$dom_info = 'The domain name <b>'.$my_whois->compl_domain.'</b> is free. ';
		} elseif ($test == 0) {
			$dom_info = 'The domain name <b>'.$my_whois->compl_domain.'</b> is already registered.';
		} else {
			$dom_info = "Can't access the server, please try again later.";
		}
	} else {
		$dom_info = "The value inside the domain field is empty or not valid, only letters, numbers and hypens are allowed.";
	}  

    $objResponse->addAssign('whois_result', 'innerHTML', $dom_info);

    return $objResponse;
}

$xajax = new xajax();
$xajax->registerFunction('myFunction');
$xajax->processRequests();

And this is the form (place it inside your websites body)

<form id="cform">
        <input type="text" name="domain" size="25" maxlength="63" value="" />
        <span style="font-size:1.2em;font-weight:bold;">.</span>
        <?php echo $my_whois->create_tld_select(false); ?>
        <input type="button" id="subbtn" value="Check" onclick="xajax_myFunction(xajax.getFormValues('cform'));" />
</form>
<p id="whois_result">

NOTE: This example code is using an older xajax version, check the xajax website for updates. This quick tutorial is not about how-to use xajax, we advice to check the beginner tutorials on the xajax website.

Thats all, check our new demo page to learn how it works.

Comments / discussions

Olaf posted on 2008-08-20 14:45:43 #

do you like some fancy loading indicator?

Place this code at the end of your request form:

<script type="text/javascript">
		<!--
		xajax.loadingFunction = function() {
		  xajax.$('loadingMessage').style.display='inline';
		};
		function hideLoadingMessage() {
		  xajax.$('loadingMessage').style.display = 'none';
		}
		xajax.doneLoadingFunction = hideLoadingMessage;
		// -->
		</script>
		<span id="loadingMessage" style="margin-left:10px;display:none;">

		<img src="/images/indicator.white.gif" alt="Progress..." />
		</span>

Search Google for "Ajax activity indicators" to find some cool loading indicator images.

vurkun posted on 2009-07-14 13:38:19 #

this system please complete download link?
ı am from turkey

Olaf posted on 2009-07-14 13:48:46 #

Everything you need is on this forum/website. Of course you need some PHP/html/javascript knowledge.

The tools on this site are for web developer.

byen posted on 2010-09-30 10:18:52 #

hi Olaf this one really great idea thanks for this nice advise,..

brycelarge posted on 2010-10-06 14:47:21 #

Hi

Nice work.

Im having trouble getting this to work. I have never herd of xajax before and from your code example i uploaded this to my site and ran it. I got this error: Class 'xajax' not found no i must need the ajax class. Please could you assist me with some more in depth instructions.

Thanks again

Olaf posted on 2010-10-06 18:59:42 #

Hello,

there is no complete download, you need to start with the non-xajax version and if this works for you, extend the class / script with the code above. You need to download xajax from the 3rd party website.

brycelarge posted on 2010-10-07 07:33:12 #

Hi I downloaded xajax from the third party website. But there are so many files i have no idea where to start. I did start with the standard script and it works fine. Sorry im new to coding and im learning everyday. Maybe you could email me the xajax class (file) i need to be using? Sorry to be a pain. Thanks again.

Olaf posted on 2010-10-07 07:58:03 #

Hi,

great that you try to learn :
Do you tried the Xajax examples to become familiar with their code?
They have some really easy beginner tutorials. About the error you got before you need to check that all file locations and includes are right

brycelarge posted on 2010-10-07 08:08:46 #

Hi

I have had a look at some of their code. I use Codeigniter PHP Framework for my website. So im still trying to load xajax as a library.

Im sure after some time ill come right.

Thanks again for sharing your code!

Olaf posted on 2010-10-07 08:17:18 #

Hi,

maybe that the framework is the problem. It's quite common that 3rd party classes doesn't with other frameworks (out of the box).
How about using the jQuery to create a Ajax whois function?

brycelarge posted on 2010-10-07 12:07:37 #

Hi. i managed to get it all working.

One more question i want to add more servers like co.za or za.net where can i find the whois server information?

Olaf posted on 2010-10-07 12:50:15 #

Quote from: brycelarge
"Hi. i managed to get it all working.
One more question i want to add more servers like co.za or za.net where can i find the whois server information?"

There is no information (you need to search google or the particular sites)
Inside the class zip is a script called "whois_servertest.php" use this script with each new server and find out what kind of response you need to parse.

Another way is to use the "whois" tool from the command line (linux):

~$ whois google.co.za
Registered
%referral url:http://www.coza.net.za/cgi-bin/whois.sh?Domain=google
~$ whois go0ogle.co.za
Available

fredcarter posted on 2010-10-15 01:38:13 #

Hi

I have another whois that works with this info for ".co" and ".com.co":

.com.co|http://whois.co/co/whois-co.cgi?TLD=co&dn=|HTTPREQUEST-no records matching
.co|http://whois.co/co/whois-co.cgi?TLD=co&dn=|HTTPREQUEST-no records matching

I have tried changing the url but it does not work? How could be the right sintaxis?

Thanks.

Olaf posted on 2010-10-15 06:39:55 #

Hi Fred,
your question doesn't seems to be related to this topic, please open a new topic with more detailed information about what you like to do ;)

fredcarter posted on 2010-10-15 21:08:15 #

hi. sorry if I could not explain it well.

I am talking about the file "server_list.php". I need use the whois with ".com.co" and ".co"

I have tried with : $servers['com']['address'] = "whois.co"; and does not work. Also I have tried other combinations.

My question is how could be the right sintaxis in "server_list.php" to work with ".com.co and .co"?

I have another script that works with this data:

.com.co|http://whois.co/co/whois-co.cgi?TLD=co&dn=|HTTPREQUEST-no records matching
.co|http://whois.co/co/whois-co.cgi?TLD=co&dn=|HTTPREQUEST-no records matching

Thanks.

Olaf posted on 2010-10-16 10:16:48 #

Hi,
I'm sorry whois interfaces which work with port 80 are not supported right now.
Check the solution above how you can query .co.za domain names.

This is just a workaround, but should work if you test a domain for new registrations (this should work for most extensions)