I tried $_SERVER['HTTP_HOST'] & $_SERVER['SERVER_NAME'], but they both return sub.domain.com, I want it to check if the URL is sub.domain.com, or just domain.com.
Script is run on sub.domain.com and they BOTH return the same data.
$_SERVER['HTTP_HOST'] returns: sub.domain.com
$_SERVER['SERVER_NAME'] returns: sub.domain.com
I wish to obtain only the domain.com portion of the url. Since the script may run on any subdomain name, I am unsure of how to do so since both of the above variables return the same information.
I would check HTTP_HOST. Usually both are the same, but sometimes SERVER_NAME is set differently. When in doubt, check them both.
http://php.net/manual/en/reserved.variables.server.php
As for how to check them, you could do a string replace on it for the primary domain name and see if the result string is empty. Anything left would be the subdomain.
As far you’re looking for some trivial string operation, here the last two parts: