Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Website name generator Database Problem

steveo7502

New Coder
Hi everyone,

I’m using a freelance platform to create a website generator website. The general idea is that the user inputs a keyword, then an algorithm appends prefixes and suffixes to create a unique name. My developer has given me two options.

  1. One is to have an API query Godaddy or Bluehost and display results as per their availability on the website generator’s homepage. A click through on each name would display further information about the chosen name including similar options and social media availability on FB and twitter.
  2. Two is for the algorithm to query a database regarding whether a particular domain name is available or not. Here my developer states that all domain names would have to be entered manually through the backend so that they show up automatically on the front end. He states that all things about the site would be automatic except domain names I add individually or through an excel/xml file in the backend.
The developer claims that the second option is faster since website functioning would remain local and would not have to use an off-site API like an affiliate one from Bluehost. However, I really don’t understand why would I ever want to add anything to any database. Surely for a website generator the site is simply receiving the input from the visitor and creating a new word. Why would I add domain names to a database when my website is generating them? He states that with option one, I would add domain names manually to a database either individually or one at at time. He says that the admin should search domains accordingly and add them manually through Bluehost search engine and then those domains will auto-verify their availability.

However, I absolutely fail to see where I would get these names from? Surely there must be millions of names? I’m clearly missing something obvious as this is truly perplexing to me.

Can anyone help me understand this issue?

Thanks,
Steve
 
I'm not sure if I'm missing the point either. But from my understanding, I'm expecting I'd put in a keyword and your website would generate domain names with availability right? If this is the case, I could understand a database of prefixes or suffixes, but I'm not sure where a database of specific domain names would come into it?

Perhaps you can have your developer elaborate on the implications of the 2nd option. ie. What domains are you to put in? How does that help with generating new domains? Where does the data, to say if a domain is available, come from?

As I said, perhaps I'm misunderstanding too but if it was me, I'd be using an external service to check if specific domains are available and my website would just generate a list of those domains to check based on keywords input from the user.
 
Here's how I would do it... (I coded like half the project for you lol, I'm bored today)

Your local database would only store:
- prefixes
- suffixes
- domain extensions

Front end page would have the text / input field & a submit button:
- User types in domain (ex: "codeforum")

Front end submits the typed in domain to a script (for me, I would use JavaScript on frontend page to send request to like "scripts/find-domains.php")
- Script grabs prefixes & suffixes from database
- Generates a list of possible domains (thecodeforum, acodeforum, codeforumplace, codeforums)
- For each generated domain, add domain extensions (thecodeforum.org, thecodeforum.net, thecodeforum.com, etc)
- Script uses an API to check if domain is available.

I personally would use PHP's gethostbyname() function to grab the domain's IP address.
gethostbyname is very simple to use. It looks up the domain - It returns an IP address if the domain exists. If it does NOT exist, it returns the domain name (so if you do gethostbyname("google.com"), it will return the IP, but if you do like gethostbyname("blajdlfksjdflksfln2302naknflsdkfn203nknf.com") it will return " blajdlfksjdflksfln2302naknflsdkfn203nknf.com" which means it's available.

Something that is important to do is to add an extra period after the domain ( like searching for 'google.com.' instead of 'google.com' )-- This is because there are known problems when you do not add a trailing period at the end. This is why you see if(gethostbyname($string . ".") == $string . "."){ } in the code. It makes sure that the PHP knows to search for an external domain - otherwise it will try to search for like... "slkdfjslfk239nsdf.com.yourdomainhere.com" which is obviously false.

------

I just wrote this code... took me about 10 minutes or so to code it, then about 15 minutes of testing & fixing things. I've never made a domain checker, but have always wanted to. This was a fun one - Thank you for asking a great question, I'm happy as heck that this works :) I will probably convert this into a text or video tutorial for my site Nerdi.org in the future

You can see my working example here:
https://nerdi.org/domain-finder

Note:
I wrote this code to get it done quickly - it is NOT efficient or using a database obviously.
The best way to make this script faster would be to cycle through all the TLDs in a for loop (faster than foreach).
Inside of your for loop for the TLDs, you would check all the domain availability without a prefix or suffix first.
Then you would check all the prefix+keyword availability, inside a for loop for all prefixes.
Inside the same loop for all the prefixes, you would have a loop for all the suffixes - inside this final loop you would check all the keyword+suffix availability AND then all the prefix+keyword+suffix availability.
This would cut down the time it takes for the script to run! In my example below I went with a "get it done" method to show you examples. It's not efficient because there are too many loops - as you can see, we loop through TLDs, prefixes, suffixes multiple times.


PHP:
<?php
    $prefixes = array("the", "a", "best", "online", "");
    $suffixes = array("spot", "place", "hub", "magic", "community", "family", "area", "zone", "");
    $tlds = array(".com", ".org", ".net", ".co", ".me", ".io", ".biz", ".bz");
    $keyword = "codeforum";
    $checked = array();
    foreach($prefixes as $prefix){
        $temp_phrase = $prefix . $keyword;
        foreach($tlds as $tld){
            $temp_domain = $temp_phrase . $tld;
            if(isset($checked[$temp_domain])){ continue; }
            if(gethostbyname($temp_domain . ".") == $temp_domain . "."){
                echo "$temp_domain is available!<br>";
            } else {
                echo "$temp_domain is not available!<br>";
            }
            $checked[$temp_domain] = true; // means we already checked this domain
        }
    }
    foreach($suffixes as $suffix){
        $temp_phrase = $keyword . $suffix;
        foreach($tlds as $tld){
            $temp_domain = $temp_phrase . $tld;
            if(isset($checked[$temp_domain])){ continue; }
            if(gethostbyname($temp_domain . ".") == $temp_domain . "."){
                echo "$temp_domain is available!<br>";
            } else {
                echo "$temp_domain is not available!<br>";
            }
            $checked[$temp_domain] = true; // means we already checked this domain
        }
    }
    foreach($suffixes as $suffix){
        $temp_phrase_suffix = $keyword . $suffix;
        foreach($prefixes as $prefix){
            $temp_phrase_prefix = $prefix . $temp_phrase;
            foreach($tlds as $tld){
                $temp_domain = $temp_phrase_prefix . $tld;
                if(isset($checked[$temp_domain])){ continue; }
                if(gethostbyname($temp_domain . ".") == $temp_domain . "."){
                    echo "$temp_domain is available!<br>";
                } else {
                    echo "$temp_domain is not available!<br>";
                }
                $checked[$temp_domain] = true; // means we already checked this domain
            }
        }
    
    }
?>

You would then make it so prefixes & suffixes are in the database, as our the desired domain extensions.
Then instead of using $keyword = "stringhere"; you would have something like $keyword = $_POST['keyword-search'];
Just remember - whenever you are using user submitted data you should sanitize/validate the data! You need to make sure you do not allow people to hack your site... basically you want to make sure they don't submit like a malicious piece of code in the text field.

If you are selling code to someone let me know - My company charges $35-55 per hour, but we get things done fast. I could optimize the code, hook it up to the database, and give it a frontend view... If you are selling your coding services and want to turn a profit then let me know - we can work out a deal so you make some money and I or one of my programmers will write the code for you :)
 
Last edited:
I'm not sure if I'm missing the point either. But from my understanding, I'm expecting I'd put in a keyword and your website would generate domain names with availability right? If this is the case, I could understand a database of prefixes or suffixes, but I'm not sure where a database of specific domain names would come into it?

Perhaps you can have your developer elaborate on the implications of the 2nd option. ie. What domains are you to put in? How does that help with generating new domains? Where does the data, to say if a domain is available, come from?

As I said, perhaps I'm misunderstanding too but if it was me, I'd be using an external service to check if specific domains are available and my website would just generate a list of those domains to check based on keywords input from the user.
This was my understanding, but developer does not elaborate as he says that is up to me.
 
In that case, perhaps it's better to clarify the requirements to make sure that you're both on the same page.

I appreciate that this is a freelance platform you're using so there might not be any (much) formality in the approach but communication is key. For my development projects that include a client, I'd try to deliver some kind of requirement specification so that the client (you) know exactly what you're getting at a high-level. Eg. There will be an input box in which users will input keywords, from which we will generate a list of domains by combining those keywords with pre-defined affixes and domain extensions. The service will then check each domain to see if it is available.

I'm not sure of the scale of the project outside of this task but I have always found that regular communication and updates can help to keep the project from veering off course. That already almost sounds the case here with what I think is crossed-wires / misunderstanding.

If it was me, your database would be to manage your prefixes/suffixes and I'd be using an API to determine if the generated domain name was available. (Who Data, Namecheap or similar) You can do it manually as in the script above that was kindly shared but (whilst it has its advantages doing it yourself) you're more likely to get accurate results from providers who deal in this stuff. The tradeoff being there is a cost to lookup of course.

Good luck! Let us know how it goes and if you have any more questions shout up :)
 
In that case, perhaps it's better to clarify the requirements to make sure that you're both on the same page.

I appreciate that this is a freelance platform you're using so there might not be any (much) formality in the approach but communication is key. For my development projects that include a client, I'd try to deliver some kind of requirement specification so that the client (you) know exactly what you're getting at a high-level. Eg. There will be an input box in which users will input keywords, from which we will generate a list of domains by combining those keywords with pre-defined affixes and domain extensions. The service will then check each domain to see if it is available.

I'm not sure of the scale of the project outside of this task but I have always found that regular communication and updates can help to keep the project from veering off course. That already almost sounds the case here with what I think is crossed-wires / misunderstanding.

If it was me, your database would be to manage your prefixes/suffixes and I'd be using an API to determine if the generated domain name was available. (Who Data, Namecheap or similar) You can do it manually as in the script above that was kindly shared but (whilst it has its advantages doing it yourself) you're more likely to get accurate results from providers who deal in this stuff. The tradeoff being there is a cost to lookup of course.

Good luck! Let us know how it goes and if you have any more questions shout up :)
I couldn't agree more - just because a domain doesn't resolve to an IP doesn't mean it doesn't exist. There are times when a domain is registered, reserved by a registrar, or unavailable to the public, but they aren't attached to an IP address. It's important to use a proper API or come up with other methods to find out if a domain is available. My script above was more for fun (for me), but hopefully will prove useful for OP :)

There are also resources/libraries such as "whois" and related code that performs a lot of this for us... like "whois domain.com" and it will return information about the domain including whether or not it is registered or available.
 
Back
Top Bottom