Hi, I was wondering how i would get this script to work in an ajax style. At the moment i have this submitting to another page which checks but would be really good if i could type in the domain and select an ext and it automatically comes up if it available or not. Here is the code: <?php //Domain Checker function check_domain($domain,$ext){ $server="whois.networksolutions.com"; $nomatch="No match for"; $output=""; if(($sc = fsockopen($server,43))==false){ return true; } fputs($sc,"$domain.$ext\n"); while(!feof($sc)){ $output.=fgets($sc,128); } fclose($sc); if (eregi($nomatch,$output)){ return true; } else { return false; } } //Sample usage $is_registered = check_domain("sonimager","com"); if($is_registered == true){ echo "Domain Taken";}else{echo "Domain is free";} ?> Code (markup): Cheers, Adam
domain.php <?php $domain = $_GET['domain']; $ext = $_GET['ext']; //Domain Checker function check_domain($domain,$ext){ $server="whois.networksolutions.com"; $nomatch="No match for"; $output=""; if(($sc = fsockopen($server,43))==false){ return true; } fputs($sc,"$domain.$ext\n"); while(!feof($sc)){ $output.=fgets($sc,128); } fclose($sc); if (eregi($nomatch,$output)){ return true; } else { return false; } } //Sample usage $is_registered = check_domain($domain , $ext); if($is_registered == true){ echo "Domain Taken";}else{echo "Domain is free";} ?> PHP: ajax.php <html> <head> <title>Domain Age Calculator</title> <script language="javascript" type="text/javascript"> //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var domain = document.getElementById('domain').value; var ext = document.getElementById('ext').value; var queryString = "?domain=" + domain + "&ext=" + ext; ajaxRequest.open("GET", "domain.php" + queryString, true); ajaxRequest.send(null); } </script> </head> <body> <input type="text" size="30" name="domain" id="domain"> <select name="ext" id="ext"> <option value="">select extension</option> <option value="com">com</option> <option value="org">org</option> <option value="net">net</option> <option value="info">info</option> <option value="edu">edu</option> </select> <input type="button" value="Check" onclick="ajaxFunction()"><br><br> <b>Enter the domain name without www. Correct</b> = gmail.com <b>Wrong</b> = www.gmail.com <br><br> <div id="ajaxDiv">The Message will be shown here</div> </body> </html> PHP: domain.php is the server side script.
Thanks a lot coderbari's this works great. Just one thing though, the script comes back with domain name taken even if the domain is available. Any ideas on why this is happening?
I also got that error.This is may be bcoz of your written codes.I have no idea about that part.You wanted it to AJAXify and i gave you the idea.
There is a person giving a script like this out for free in the freebies forum. http://forums.digitalpoint.com/showthread.php?t=579457