Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in php, phpremoteaddr
Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in php
1. REMOTE_ADDR: IP address of the user's computer browsing the current page
2. HTTP_X_FORWARDED_FOR: view the gateway of the user's computer on the current page
3. HTTP_CLIENT_IP: Client ip Address
Use $ _ SERVER ["REMOTE_ADDR"] in PHP to obtain the IP address of the client. However, if the client is accessed by a proxy SERVER, the IP address of the proxy SERVER is obtained, instead of the real client IP address. To obtain the real IP address of the client through the proxy SERVER, use $ _ SERVER ["HTTP_X_FORWARDED_FOR"] to read it.
However, 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 Proxy Server IP addresses.
Note that if the client is not accessed through the proxy SERVER, the value obtained from $ _ SERVER ["HTTP_X_FORWARDED_FOR"] will be null.
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)
I. No proxy server is used:
REMOTE_ADDR = your IP address
HTTP_VIA = no value or no display
HTTP_X_FORWARDED_FOR = no value or no display
Ii. Usage of Transparent proxy server: Transparent Proxies
REMOTE_ADDR = IP address of the last Proxy Server
HTTP_VIA = Proxy Server IP Address
HTTP_X_FORWARDED_FOR = your real 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.
This type of proxy server still forwards your information to your access object, which cannot hide your real identity.
Iii. Normal Anonymous proxy server: Anonymous Proxies
REMOTE_ADDR = IP address of the last Proxy Server
HTTP_VIA = Proxy Server IP Address
HTTP_X_FORWARDED_FOR = 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. destorting Proxies
REMOTE_ADDR = Proxy Server IP Address
HTTP_VIA = Proxy Server IP Address
HTTP_X_FORWARDED_FOR = random IP address. When multiple proxy servers are used, the value is as follows: 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. High Anonymity Proxies (Elite proxies)
REMOTE_ADDR = Proxy Server IP Address
HTTP_VIA = no value or no display
HTTP_X_FORWARDED_FOR = no value or no value is displayed. When multiple proxy servers are used, the 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.
Source: http://www.cnblogs.com/andhm/archive/2010/12/18/1910030.html