Spliting a hostname

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Spliting a hostname

Post by alex.barylski »

I know of many URI classes (including the one in Zend) however none seem to break a hostname into smaller units for you, particularly sub-domain, domain and TLD.

Initially it may seem possible to just split the domain on '.' and be done with it, however what about domains where there are arbitrary number of sub-domains and TLD?

Is this even possible? I have seen sites that seem to offer multiple sub and TLD's, such as:

*.mb.ca - is popular for goverment web sites (mb.ca appears to be the TLD?)

I have also seen commercial web sites do something like

winnipeg.mb.domain.ca (winnipeg.mb appears to be the sub-domains)

If this is possible, knowing this makes just simply splitting on periods risky. What alternatives do I have?

Do I acquire a list of TLD's and figure out the TLD, the domain and sub-domains from there?

I realize it's very unlikely for a web site to have more than one sub-domain but it could happen so I'd rather build with that awareness.

Any ideas?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Spliting a hostname

Post by Jenk »

'.' is the splitter. There are no TLD's with fullstops/periods in them. Prime example is the UK's '.co.uk' The TLD is actually .uk and the .co is a sud-domain of that TLD. (Hence why we have .gov.uk, .mod.uk, etc.)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Spliting a hostname

Post by alex.barylski »

EDIT | Just looked at GoDaddy...they seem to have TLD's for sale with periods (ie: .net.cn) why would they offer that and not just .cn? Does this mean GoDaddy has purchased the domain net.cn and is simply selling off it's sub-domains?

OK thats what I figured but wasn't sure about and figured I'd ask.

So TLD's are a list I can get from GoDaddy or similar source and the last element in a split would be the TLD, one up would be the domain and anything further are sub-domains?

Thanks for the heads up :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Spliting a hostname

Post by VladSun »

As far as I remember, one is not allowed to register a domain name which is:
- shorter than 3 symbols (WTF??? hp.com ???);
- is the same as one of the top-level domains (e.g. org.com)

It's up to the ccTLD registrar to decide whether a second level domains will be used (e.g. co.uk) or not.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Spliting a hostname

Post by jayshields »

VladSun wrote:- shorter than 3 symbols (WTF??? hp.com ???);
Nah that's not true. There are many exceptions to that rule.

http://en.wikipedia.org/wiki/Single-let ... el_domains

One which is being advertised on UK TV loads now is lv.com.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Spliting a hostname

Post by VladSun »

jayshields wrote:
VladSun wrote:- shorter than 3 symbols (WTF??? hp.com ???);
Nah that's not true. There are many exceptions to that rule.

http://en.wikipedia.org/wiki/Single-let ... el_domains
In fact, it's true:

http://en.wikipedia.org/wiki/Single-let ... el_domains
Two-letter domain names are also restricted to prevent confusion with country-codes. However, this restriction was enacted long after domain names became popular, so there are many existing registrations in the old top-level domains, though they are prevented in most of the new ones such as .info.


:P
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Spliting a hostname

Post by alex.barylski »

Stupid authorities...how does that Pennywise song? Anyone know what song I'm talking about? :P 8)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Spliting a hostname

Post by Jenk »

PCSpectra wrote:EDIT | Just looked at GoDaddy...they seem to have TLD's for sale with periods (ie: .net.cn) why would they offer that and not just .cn? Does this mean GoDaddy has purchased the domain net.cn and is simply selling off it's sub-domains?

OK thats what I figured but wasn't sure about and figured I'd ask.

So TLD's are a list I can get from GoDaddy or similar source and the last element in a split would be the TLD, one up would be the domain and anything further are sub-domains?

Thanks for the heads up :)
GoDaddy are telling a white lie. They are the domains that GoDaddy are permitted to sell, not the TLD's..

http://en.wikipedia.org/wiki/List_of_In ... el_domains
SeaJones
Forum Commoner
Posts: 48
Joined: Tue Jun 30, 2009 5:40 pm

Re: Spliting a hostname

Post by SeaJones »

RE: Two letter domains

It *used* to be the case that domains registered through InterNIC (.com .org etc) could only have two letters if one was a number. Some registrars never enforced this, some actually still do. InterNIC will still delete stuff that they consider to be conflicting or confusable with other domains especially country-code SLDs, although they barely ever seem to bother. The rule seem to basically be "don't take the <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>".

All of this said, HP.com was registered when it should've been impossible, and the InterNIC could've happily deleted it, but it didn't. If they had had an initialism that conflicted with a country code they might've had more trouble.

A good example of this kind of loosely enforced rule system is the .name domain type, which according to rules should be first.last.name, but loads of people don't do that, and there is no requirements for the two names to actually be yours. Thousands of .name domains are registered with only one name attached.

Nominet, on the other hand, can be quite strict. But even then only when they can be arsed.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Spliting a hostname

Post by Weirdan »

PCSpectra, for a list that uses layman's definition (where '.co.uk' is a tld) you may consult FF source code - it maintains that list to decide whether to allow crossdomain cookies (for example it would allow a cookie for .example.com to be set from a.example.com, but would not allow a cookie from a.co.uk to be set for .co.uk).
Post Reply