Wouldso would one obtain the root DNS entry from $_SERVER['HTTP_HOST']?


example.co.united kingdom

world wide web.example.com


forum.example.co.united kingdom


example.co.united kingdom



example.co.united kingdom

EDIT: Research list is very lengthy

I believe that's a little ill-defined.

You could attempt doing DNS searches for every parent record before you locate one that does not return a b record.

As is available discovered, some nations make use of a TLD only (example: .tv, .us), others subdivide their country TLD (example: united kingdom).

Ideally, you will need a research list (it will not be lengthy) of approved TLDs, and, if subdivided, the TLD with each subdivision (e.g., ".co.united kingdom" rather than ".united kingdom"). That will explain which "dots" (in the right) to help keep. Then move one us dot left of this (if found) and chop everything before it.

With no research list, you are able to exploit the truth that the subdivisions (.co, etc.) are only concerned with nations (that have 2-letter TLDs) and therefore are AFAIK only ever 3 figures themselves and therefore are always letters, to help you most likely recognize all of them with a regex pattern.

Edit: Nevermind, the particular listing of public suffixes is a lot more complex. You are gonna need to make use of a research table to determine exactly what the suffix is, return to the prior us dot, and trim left. RegEx is really a poor solution here. Rather, keep listing of suffixes inside a Dictionary, then test against your domain title, lopping off one dotted portion at any given time in the left before you hit a match, adding back the part you simply trimmed off.

/[^.]+.[steered clear oflistofdomain names]$/

I believe that will work.

Note: as stated within the comments, this process does not really work in most cases. The reason behind this really is that some top-level domain names do resolve to IP addresses, even when most don't. Therefore you cannot identify if your given title is top-level or pseudo-top-level domain title basically by checking if we have an Ip. Regrettably, this most likely implies that the only real option would be a research list, given how inconsistently treated top-level domain names are used.

Once more: don't depend around the code below to dedicate yourself you. I let it rest for educational reasons only.

There's a method to do that with no research list. Their email list might be hard to rely on or incomplete, whereas this process is certain to work:


function get_domain($url) finish_pieces = $dots $finish_pieces >  $finish_pieces--) finish(explode('.', $url, $finish_pieces))

        if (dns_check_record($test_domain, 'A')) 


    return $domain

$my_domain = get_domain('www.robknight.org.uk')

echo $my_domain


Within this situation, it'll output 'robknight.org.uk'. It might work as well for .com, .edu, .com.au, .ly or whatever some of the best-level domain you are operating on.

It functions by beginning in the right and carrying out a DNS check up on the very first factor that appears like it may be a viable domain title. Within the example above, it begins with 'org.uk', but finds out that this isn't a real domain title, but is really a ccTLD. After that it moves onto check 'robknight.org.uk', which is valid, and returns that. When the domain title have been, say, 'www.php.net', it might have began by checking 'php.net', the industry valid domain title, and might have came back that immediately without looping. I ought to also explain when no valid domain title is located, a clear string ('') is going to be came back.

This code might be unacceptable for processing a lot of domains inside a short period of time because of time taken for DNS searches, but it is perfectly acceptable for single searches or code that is not time-critical.