How to programaticly tell a TLD from a sub domain?

Red Squirrel

No Lifer
May 24, 2003
70,565
13,802
126
www.anyf.ca
How would I programaticly tell if a user specified domain name is actually a full valid domain, and not a TLD that is a sub domain? Ex:

user enters co.uk as their domain, this should be invalid as co.uk is actually a TLD even though it is like a sub domain.

My original idea involved importing a list of all the sub domain style TLDs into my program, but that list is massive. How do programs like cpanel handle this when a user enters a domain?
 

Colt45

Lifer
Apr 18, 2001
19,720
1
0
if ( tld == (uk || ck || etc) && (subdomain == ( co || org || gov || plc || etc ) )){
/* fail */
}

something like that i guess..? It's gonna be ugly if you want every possible thing on earth though. gonna add dyndns.org and ath.cx etc etc etc too? doesn't seem feasible.
 

Red Squirrel

No Lifer
May 24, 2003
70,565
13,802
126
www.anyf.ca
There are actually thousands of those domains. Or should I just not bother, put only the well known ones, and let the admin (end user of my app) add them as required? I mean, how many people are actually going to use .ath.cx domains and such? Probably not worth the effort right?

Or is there maybe some kind of website it can query or something?
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
I would list all the candidates (somehow... either in a file or dynamically from a trusted site, or both), and then check each time.

It would be better to architect whatever system you're building to not care about this potential error case.
 

Red Squirrel

No Lifer
May 24, 2003
70,565
13,802
126
www.anyf.ca
It would be better to architect whatever system you're building to not care about this potential error case.

Which pretty much goes back to my question. There must be a way to programaticly check without using a premade list.

And the reason I need to know this is, for example say someone adds the addon domain "co.uk". That will screw up, you can't register that domain, nor make it point to any DNS record. It's not a domain even though it structurally is. If someone picks that then the system will say that user owns that domain, so another user wont be able to add say, something.co.uk.

In a legit domain these checks are important as if someone actually owns example.com and adds it as an add-on domain, only that user will be allowed to make subdomains for it.

One thing I thought of that I could check is just allow domains that resolve. That would force users to create their DNS record first, but guess that's not really a huge deal.

Anyone know how cpanel does it? I'm sure it must handle this issue in some way or form, being a pretty big and popular system.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Which pretty much goes back to my question. There must be a way to programaticly check without using a premade list.

And the reason I need to know this is, for example say someone adds the addon domain "co.uk". That will screw up, you can't register that domain, nor make it point to any DNS record. It's not a domain even though it structurally is. If someone picks that then the system will say that user owns that domain, so another user wont be able to add say, something.co.uk.

In a legit domain these checks are important as if someone actually owns example.com and adds it as an add-on domain, only that user will be allowed to make subdomains for it.

One thing I thought of that I could check is just allow domains that resolve. That would force users to create their DNS record first, but guess that's not really a huge deal.

Anyone know how cpanel does it? I'm sure it must handle this issue in some way or form, being a pretty big and popular system.

I don't know if my host uses cpanel, but you have to create the domain before you can do anything with it. If I were designing this I would definitely create the domain and DNS pointers first, then allow them to create subdomains.
 

Red Squirrel

No Lifer
May 24, 2003
70,565
13,802
126
www.anyf.ca
I don't know if my host uses cpanel, but you have to create the domain before you can do anything with it. If I were designing this I would definitely create the domain and DNS pointers first, then allow them to create subdomains.

Hmm I might do that then, only allow them to add a add-on domain if it resolves. So it will stop people from adding on.ca or co.uk etc as an addon domain. It's already setup so sub domains can only be added if you "own" the domain.

Now what about special cases like no-ip.org and what not? Should I maybe just have checks for those? What I could do is just make them act like TLDs, so when I do my validation for if an inputted domain is valid it could check against those. I could ship the product with the popular ones and admins could add their own if they need to.
 
Last edited:

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Now what about special cases like no-ip.org and what not? Should I maybe just have checks for those?[/q]
What makes no-ip.org a special case?

[q]I could ship the product with the popular ones and admins could add their own if they need to.[/q]

Don't do that. What you think is a popular/correct/logical choice is probably not what your clients will think is a popular/correct/logical choice.
 

Red Squirrel

No Lifer
May 24, 2003
70,565
13,802
126
www.anyf.ca
Now what about special cases like no-ip.org and what not? Should I maybe just have checks for those?[/q]
What makes no-ip.org a special case?

[q]I could ship the product with the popular ones and admins could add their own if they need to.[/q]

Don't do that. What you think is a popular/correct/logical choice is probably not what your clients will think is a popular/correct/logical choice.

It will be editable. So by default it will probably be empty but then they can be added.