I have a static domain of dev.example.com
with wildcard subdomains like so *.dev.example.com
.
I need to detect the name of the current wildcard subdomain. So if I'm browsing sub.dev.example.com
how do I get "sub"?
$env_domain = dev.example.com;
$subdomain = array_shift( explode( '.', $_SERVER['HTTP_HOST'] ) ) .'.'. $env_domain;
echo $subdomain;
Currently, this returns dev
. I need it to return sub
.
I'm thinking the best practice here would be to return the most low-level domain (the first subdomain).
Note that I'm not parsing a URL, but a given domain.