Avatar ·

What is the difference between HTTP_HOST and SERVER_NAME in PHP? Proper usage

Hello everyone! I'm a beginner in PHP and trying to understand server variables. I often see in other developers' code the use of `$_SERVER['HTTP_HOST']` and `$_SERVER['SERVER_NAME']`. At first glance, both return the host name, but I noticed that sometimes they give different values. For example, I have a simple script: ```php '; echo 'SERVER_NAME: ' . $_SERVER['SERVER_NAME'] . '
'; ?> ``` On a local server (OpenServer), both show `localhost`. But when I uploaded the site to hosting, I noticed that when accessing via IP address, `HTTP_HOST` shows the IP, while `SERVER_NAME` shows the domain name. Also, I've heard that `HTTP_HOST` can be spoofed through HTTP request headers, which creates a vulnerability. Please advise: