I want to create something that does a WHOIS query to see if a domain is available. Now, I've found quite a bunch of ready-made scripts for that, but they all seem to be the same in that you need to specify the base, and then choose which extensions you want and it will do that (so for example, enter 'test', check .com and it will check if test.com is available)
However, I'm trying to do something slightly else. The thing I want it to do is check if the user has entered just the base or the full URL, and then do one or multiple queries accordingly. Example:
If the user enters 'test', I want the script to check for test.com, test.org, test.net, etc. If the user enters 'test.com', I want the script to check JUST for test.com.
I really don't know what to build upon, but Mike Nott's PHP Whois Script looks okay. Of course, suggestions are always welcome.
Now I'm guessing the script flow should go something like this:
- User enters query
- Script checks for spaces
- Script checks if user entered just a base or a full domain name (I'm guessing the way to go about this is to check if there's a dot in there)
- If the user entered a full domain name, separate the base and the TLD and store them both in variables and store the 'status' somewhere ($full = true/false)
- if ($full = true) {check corresponding whois servers for $base.com $base.net, etc};
- if ($full != true) {see what the right server for $tld is and check that one for $base.$tld}
- Output results
Of course, if there's a script that does this already, let me know.
Edit: Just so you know, I can do simple if statements and the likes, but steps 3, 4, 5 and 6 in my 'workflow' are the parts I can't figure out.
Edit 2: Thanks for all of your answers, guys! Marcus Adam's theories are indeed valid. My domain reseller (the guys I'm getting my domains from) doesn't offer second-level TLD's like .co.uk though, so that's not a problem. They also don't support IDNs.
From the answers of you guys, I came to the conclusion that the explode function is used to separate the domain name. However, what will explode do when it encounters multiple dots? I'm guessing it'll just add another entry to the array, but that will cause problems. Because if the user then enters (for example) a domain ending in .co.uk, the script will take 'co' as the TLD.
Checking for more than 2 strings in the array is also not an option (I think), because if the user then enters 'sub.domain.com' the script will take 'sub' as the base and 'domain.com' as the TLD.
Also, Marcus Adams, you say that if the whois server shows 'available', that's not a guarantee it's available and I must query the registrar. But how would I go about that? Any ideas?
Thanks guys :)