Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in PHP. Source: qq398705749.iteye. comblog9638181.REMOTE _ ADDR: IP address of the user's computer browsing the current page 2. HTTP_X_FORWARDED_FOR: user's computer browsing the current page reference source: http://qq398705749.iteye.com/blog/963818
1. REMOTE_ADDR: IP address of the user's computer browsing the current page
2. HTTP_X_FORWARDED_FOR: Browse the gateway of the user's computer on the current page
3.
: Client ip address
Use in PHP to obtain the IP address of the client.
However, if the client uses a proxy server for access, the obtained IP address is the proxy server's IP address, rather than the real client IP address. To obtain the real IP address of the client through the proxy server, you must use it for reading.
However, note that not every proxy SERVER can use $ _ SERVER ["HTTP_X_FORWARDED_FOR"] to read the real IP address of the client. some of the IP addresses read by this method are still the IP address of the proxy SERVER.
Note that the value obtained by $ _ SERVER ["HTTP_X_FORWARDED_FOR"] is null.
Php code if ($ _ SERVER ['http _ X_FORWARDED_FOR '] & preg_match ('/^ ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} $/', $ _ SERVER ['http _ X_FORWARDED_FOR']) {
$ Onlineip = $ _ SERVER ['http _ X_FORWARDED_FOR '];
} Elseif ($ _ SERVER ['http _ CLIENT_IP '] & preg_match ('/^ ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} $/', $ _ SERVER ['http _ CLIENT_IP']) {
$ Onlineip = $ _ SERVER ['http _ CLIENT_IP '];
}
if ($_SERVER['HTTP_X_FORWARDED_FOR'] && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',$_SERVER['HTTP_X_FORWARDED_FOR'])) { $onlineip = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif ($_SERVER['HTTP_CLIENT_IP'] && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',$_SERVER['HTTP_CLIENT_IP'])) { $onlineip = $_SERVER['HTTP_CLIENT_IP']; }
Differences between the three attributes for obtaining the user IP address (HTTP_X_FORWARDED_FOR, HTTP_VIA, REMOTE_ADDR ):
1. no proxy server is used:
= Your IP address
= No value or no Display
= No value or no Display
II. usage of transparent proxy servers: Transparent Proxies
= IP address of the last proxy server
= Proxy server IP
= When your real IP address passes through multiple proxy servers, the value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
This type of proxy server still forwards your information to your access object, which cannot hide your real identity.
III. use of normal anonymous proxy servers: Anonymous Proxies
= IP address of the last proxy server
= Proxy server IP
= Proxy server IP address. when multiple proxy servers are used, this value is similar to the following: 203.98.1820.3, 203.98.1820.3, 203.129.72.215.
Your real IP address is hidden, but you are disclosed to the access object that you use the proxy server to access them.
IV. use of fraudulent proxy servers: Distorting Proxies
= Proxy server IP
= Proxy server IP
= Random IP address. when multiple proxy servers are used, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
It tells the access object that you used the proxy server, but fabricated a false random IP address instead of your real IP address to cheat it.
5. use of highly anonymous proxy servers: High Anonymity Proxies (Elite proxies)
= Proxy server IP
= No value or no Display
= No value or no Display. when multiple proxy servers are used, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.
The proxy server information replaces all your information, just as you directly access the object using the proxy server.
Example 1. REMOTE_ADDR: IP address of the user's computer browsing the current page 2. HTTP_X_FORWARDED_FOR: browsing the user's computer on the current page...