Today, I checked the ecshop source code and found that the $ _ server ['HTTP _ x_forwarded_host '] was used to determine the host address, for the moment, many people directly judge through $ _ server ['HTTP _ host'], but there is a problem through proxy. Please refer to the following problem description:
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"
- Host of the current request: 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" process in the middle. 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.
Source: http://stephenjqj.iteye.com/blog/429879
This is also mentioned in the PHP manual comment:
Be careful with HTTP_HOST behind a proxy server. Use these instead.
[HTTP_X_FORWARDED_FOR]
[HTTP_X_FORWARDED_HOST]
[HTTP_X_FORWARDED_SERVER]
In my situation, I used [http_x_forwarded_server] in place of [http_host] In order get the machine and hostname
Source:
Http://www.php.net/manual/zh/reserved.variables.php#65190
In http://pinds.com/2005/12/05/what-s-with-http_x_forwarded_host /,Http_x_forwarded_host
Final Solution:
$ Host = isset ($ _ server ['HTTP _ x_forwarded_host '])? $ _ Server ['HTTP _ x_forwarded_host ']: (isset ($ _ server ['HTTP _ host'])? $ _ Server ['HTTP _ host']: $ _ server ['server _ name']. ($ _ server ['server _ port'] = '80 '? '': '. $ _ Server ['server _ port']);
Question about $ _ server constant http_x_forwarded_host and http_host