Whenever we start any website first we search for the domain availability. Here we introduce a code example that How we create a custom Domain Availability Checker using WHOIS XML API And PHP also with Ajax call.
So before we start, please complete those points mentioned below, which are used for the development of Domain Availability Checker using WHOIS XML API.
- As we know we use WHOIS XML API ( domain search API), for that reason we have to Sign up for the API Key and from there we get the API Endpoint also.
- Install Postman Chrome Extension for export API integration code,
- After getting a complete API URL with API key use Postman for complete PHP CURL script.
Now we will show you a simple example of how to create a domain availability checker using PHP and AJAX. There are only 2 steps to develop a Domain Name Checker.
STEP:1
Create an HTML file for user input and that input send to the API as an argument and then we get the response.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<a href="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js</a> <input type="text" name="domain_name" id="domain_name"> <button type="submit" id="search">Search</button> <div id="container"></div> <script type="text/javascript"> $('#search').click(function() { var domain_name = $('#domain_name').val(); $.ajax({ type: "POST", url: "/textmagic-rest-php/domain_availablity.php", data: { domain_name: domain_name }, success: function(result) { //alert(result); $("#container").empty(); $("#container").append(result); } }); return false; }); </script> |
STEP:2
Now, we create a script for getting a response from API using PHP CUrl. This PHP CURL script we create using POSTMAN Chrome Extension or APP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php if(!empty($_POST['domain_name'])){ $d = $_POST['domain_name']; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://domain-availability-api.whoisxmlapi.com/api/v1?apiKey=yourkey_ZGZ&domainName=".$d, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "postman-token: 22890b81-68a3-c75c-7dc5-1d1e6e9d1cf2" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } } ?> |
On that, we provide the user input as a variable and get JSON format response.
You have also found more domain registry API integration into PHP.
On the end, if you have any issue you can comment below.
Also, check: Import and Export CSV file in PHP
Happy Coding..!
Was this article helpful?
YesNo
Can I use this in WordPress site?
Yes, you can. Create a custom page template and under the main content on that page paste these codes.
[…] Domain Availability Checker using WHOIS XML API And PHP […]