What alternative to HTTP_HOST can I use?

apache, host, php, security

Solution

Use `$_SERVER['SERVER_NAME']` for this purpose, from the docs :

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.

Problem

I have to display current server host (in PHP, but it is not very important). I don't know on which host I am. How can I do that without security issue ? If I use `$_SERVER['HTTP_HOST']`, it comes from client so I can't trust this information (it can be rewritten, I think). PS: I've read this post : How reliable is HTTP_HOST? but I did not find any response (maybe I did not search correctly...)

Original source

Related problems