Your basic approach looks sound to me. It's good to have a default in the event that the domain just happens to be something other than one of those two options (e.g., localhost or an ip address).
As for which to use, I don't really know which is better. It's helpful to checkout out what these constants mean:
'HTTP_HOST'
Contents of the Host: header from the current request, if there is one.
'SERVER_NAME'
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
This doesn't look especially informative to me.
You should try and keep in mind that these values might be manipulated by malicious users. Your code above does not look especially vulnerable to malicious manipulation.