Obtain the real IP address of the client

Source: Internet
Author: User

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.

 

Http://qq398705749.iteye.com/blog/963818

Obtain the real IP address of the client

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.