Hi there,
The SERVER_NAME is more reliable than HTTP_HOST, but yes, dependent to host configuration. But, it’s host responsibility to configure and provide proper information to the application running from its own environment.
Maybe your definition of safe is about usability and availability, but with safe as security, it’s safer to use SERVER_NAME since your host can enforce it regardless of who’s sending the request. While HTTP_HOST is something sent over the header, which the remote end could craft a value for HTTP_POST that isn’t your domain. Both are vulnerable, but at least the first one is host controlled.
Thanks for sharing.