PHP Scripting Forums » Discuss our Web Development Tutorials

[sticky]

PHP Ajax Whois example code

(2 posts)
Great offers not only for geeks!
Your Ad Here

  1. Hi,

    today we changed the Whois demo on our website:
    http://www.finalwebsites.com/demos/php_whois_script.php

    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.

    Posted 3 months ago #
  2. 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..." border="0" />
    		</span>

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

    Posted 3 months ago #

RSS feed for this topic

Reply

You must log in to post.