$ _SERVER ['HTTP_HOST'] = ip, not my server

my php script has $ _SERVER ['HTTP_HOST'] equal to ip, which has nothing to do with my ip server.

Has anyone got an easy explanation?

(I thought some bot was sending a completely invalid Host header, but I don't think it could connect to the server with the wrong host header = /)

THX

+1
source share
2 answers

HTTP_HOST provided by the client in the Host: HTTP request part. It can be changed arbitrarily, although I cannot understand why this is necessary. See the manual page .

Use $_SERVER['SERVER_NAME'] instead. This is determined by the server itself.

+9
source

The Host header has absolutely nothing to do with connecting to the web server. It is used by the web server when it is connected to route an HTTP response to a specific virtual host. Perhaps the virtual host where your script is located is the default virtual host, in which case the HTTP conversation will be redirected to it if it does not correspond to other virtual hosts.

+3
source

Source: https://habr.com/ru/post/1495080/


All Articles