How to obtain the real IP address of a real client using PHP

Source: Internet
Author: User
This article describes how to obtain the real IP address of a real client in PHP. REMOTE_ADDR is the IP address that your client uses to "Shake 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 other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.