This article describes how to obtain the real IP address (REMOTE_ADDR, HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR) of the real client in PHP, which has good reference value. Next, let's take a look at it. This article mainly introduces the PHP method for obtaining the real IP address (REMOTE_ADDR, HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR) of the real client, which has good reference value. Let's take a look at it with the small editor.
REMOTE_ADDR is the IP address when your client "shakes hands" with your server. If "anonymous proxy" is used, REMOTE_ADDR displays the IP address of the proxy server.
HTTP_CLIENT_IP is the HTTP header sent by the proxy server. If it is a "super anonymous proxy", the return value is none. Similarly, REMOTE_ADDR will be replaced with the IP address of the proxy server.
$ _ SERVER ['remote _ ADDR ']; // IP address of the access end (which may be a user or a proxy)
$ _ SERVER ['http _ CLIENT_IP ']; // proxy end (it may exist and can be forged)
$ _ SERVER ['http _ X_FORWARDED_FOR ']; // the proxy of the user's IP address (which may exist or can be forged)
The differences between the three values are as follows:
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. 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.
// Obtain the user IP address $ ip = ''; foreach (array ('http _ CLIENT_IP ', 'http _ X_FORWARDED_FOR', 'http _ from', 'remote _ ADDR ') as $ v) {if (isset ($ _ SERVER [$ v]) {if (! Preg_match ('/^ \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3} $/', $ _ SERVER [$ v]) {continue ;}$ ip =$ _ SERVER [$ v] ;}} uset ($ ip, $ v );
The above is a detailed description of how PHP gets the real IP address of the real client. For more information, see PHP Chinese network (www.php1.cn )!