Alvin Brown offers a tutorial on how to create a custom domain name suggestion tool using GoDaddy’s API.
It’s been a while since my last tutorial highlighting using GoDaddy’s API to retrieve a list of domains associated with your GoDaddy account.
Today’s tutorial aims to help create a simple tool that returns available domain names based on submitted keywords and domain ideas.
There’s no shortage of domain name suggestion tools when thinking about the name of your next product, service, business, or project.
Before diving into today’s tutorial, please review and read previous tutorials to learn how to get started using GoDaddy’s API and its various API endpoints offered to programmatically manage various aspects of your account.
At the end of this tutorial, you will find a link to download the zip file containing the entire domain name suggestion tool sample code.
It should also be noted that the tutorial code is procedural rather than object-oriented for simplicity, and is not encouraged for use in or as production-ready environments.
Another key detail to also pay close attention to is making sure that you add/replace the GoDaddy API credentials with your own credentials, or this tutorial will not work.
Without further ado, open up a text editor of your choice and let us begin.
Again, I won’t go into detail, but will give a high-level overview of the parts needed to use GoDaddy. to suggest method to retrieve a suggested list of alternative domains.
Creation of a search form for the domain name suggestion tool
From a text editor of your choice, save and name the following php file: suggest.php. Once the main file has been created, the first piece of activity to process is the HTML form used to submit the keywords. Copy and paste the following HTML code into the suggest.php:
The last 10 or so lines of code in the suggest.php contains the logic to display a suggested list of alternate domains after the form is successfully submitted.
Although contained in the suggest.php file, the results of the PHP code above are not visible from a web browser on initial page load. The form must be completed and submitted to reveal the results.
With the front end UI/UX in place, let’s dive into the functionality of the page once we’ve submitted keywords or domains for the suggested list of alternate domains.
Creating PHP logic for the domain name suggestion tool
At the very top of suggest.php file, copy and paste the following PHP logic:
The first thing to notice in the picture is the use of PHP’s built-in setter functionwhich is implemented to set the constant variable NAME OF THE SITE (i.e. Domain Suggestions).
The next set of variables to set are mission critical to authenticate and instantiate a GoDaddy API request. the API KEY and API_SECRET credentials can be obtained by visiting the API Key Management page.
After defining the critical variables for GoDaddy API authentication, the next set of variables to define are:
- add – an optional variable if you want to add alpha, numeric or alphanumeric values to submitted keywords
- typing – it is a mandatory variable
- msg – default variable used to capture and return human readable error messages to display
- searchDNAAvailable – default variable used to trigger or not display domain results each time the page is loaded or submitted. If the value is 0, no domain is displayed (i.e. initial page load). If the value is 1, the form was submitted successfully and a suggested list of alternative domains is available for display.
The PHP logic for what should happen when the form is submitted can be executed after the variables are set. The code below determines whether the submit button has been pressed or not.
If the submit button was pressed, then an error message is set by default using the msg variable. In this case, the error message is displayed if the user clicks the submit button without entering a keyword.
The next few lines proceed to clean up submitted keywords (i.e., $_POST[‘domain’] is cleaned and set as the value of key words variable) to ward off hackers attempting to hijack the search tool must be hosted on a public web server.
The last line of logic contains all the heavy lifting. If the keywords variable is not empty and is set, then the following variables are set:
- msg is set to nothing, and this now overrides the previous error message
- typing is set equal to KEYWORD_SPIN (other values available according to GoDaddy’s API documentation for the suggestion method: KEYWORD_SPIN, keyword spin, EXTENSION, extension, PREMIUM, premium, CC_TLD, cctld)
- searchDNAAvailable is set equal to 1
- look for is set equal to getDomains function, passage typing as the first argument and key words as second argument
Populating the aforementioned variable definitions closes the PHP logic to build and display the suggested list of alternate domains.
But still not so fast. If you were to open a web browser and attempt to run code up to this point, you would encounter warnings of the following undefined functions: getDomains, RemoveSpecialCharand printDomainResults.
PHP functions needed for the domain name suggestion tool
Below is a high-level overview of 3 essential functions needed to successfully complete this tutorial (each function is included in suggest.php file):
the getDomains function is the brains of finding and compiling the suggested list of alternative domains based on the source (i.e., typing variable) and keyword (i.e., key words variable). In this function exists the built-in function of PHP LOOP method that sends the API request to the suggestion method with submitted keywords and sources.
Also, feel free to modify the the country and limit variables as well as add variables to refine or expand the domain search based on GoDaddy to suggest method attributes:
- the country – two-letter ISO country code to use as a hint for the target region
- town – city name to use as a hint for the target region
- sources – sources to query (see previous section for the typer variable)
- tld – top-level domains to include in suggestions
- max length – maximum length of the second level domain
- lengthMin – minimum length of the second level domain
- limit – maximum number of suggestions to return
- waitMS – maximum time, in milliseconds, to wait for responses; if elapses, returns the compiled results up to this point
the RemoveSpecialChar The function is the simplest of the 3 functions, using PHP preg_replace and regex to remove all special characters from keyword submission.
the printDomainResults The function prepares the domain results to be presented to the web browser display using HTML. Each domain links to GoDaddy’s domain availability page to check domain availability for registration (see image below).
I encourage you to download the tutorial code, make the necessary changes, and see where this tool takes you.
DOWNLOAD dnsuggest.zip for the GoDaddy API
If manually registering domains is your strategy, or if you just need help discovering an alternative domain for your next business, idea, project, or something else, this tool aims to help you save time and money. money.
With little effort and a slight modification of the printDomainResults function, you can easily host your own domain search tool for the general public.
Going the aforementioned route could turn this tool into a profit center using affiliate services (i.e. CJ Affiliate) to associate domain registrations with domain registrars (i.e. NameCheap. com, GoDaddy, HostGator and many others…). (index index) 😉
Feel free to leave comments if you have any questions or encounter technical difficulties while implementing this tutorial.
Thanks and that’s all for now!