In PHP, we generally use $ _ server ['HTTP _ host'] to obtain the domain name or IP address of the website in the URL.
The explanation in the PHP manual is as follows:
"Http_host": the host of the current request: the content of the header information.
In general, this will not cause any problems. In some common PHP frameworks, such as pfc3 and flea are also based on this predefined variable.
However, when a program is handed over to the customer for testing in a recent project, it turns out that the redirection of the program always fails.
Finally, find out the cause: $ _ server ['HTTP _ host'] in the customer's environment, the obtained value is always the IP value of the server where the program is located in its LAN.
The reason is that the customer's company connects to the Internet through a server, and the server where our program is located is mapped out through the domain name, that is, there is a"Proxy.
Therefore, $ _ server ['HTTP _ host'] in such an environment, the obtained value is always the IP value of the server where the program is located in its LAN.
Finally, I checked a lot of information and found an alternative implementation method in the symfony framework:
Set
$ Host = $ _ server ['HTTP _ host'];
Replace:
$ Host = isset ($ _ server ['HTTP _ x_forwarded_host '])? $ _ Server ['HTTP _ x_forwarded_host ']: (isset ($ _ server ['HTTP _ host'])? $ _ Server ['HTTP _ host']: '');