PhpHTTP_X_FORWARDED_FOR, HTTP_VIA, REMOTE_ADDR differences

Source: Internet
Author: User
I. no proxy server is used: REMOTE_ADDR your IPHTTP_VIA has no value or does not show HTTP_X_FORWARDED_FOR has no value or does not show 2. Transparent use

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. general anonymous proxy servers:

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. use of fraudulent proxy servers:

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. use of highly anonymous proxy servers:

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.

Example 1: obtain the real IP address of a user,The code is as follows:

  1. Function getIp (){
  2. If ($ _ SERVER ['http _ CLIENT_IP ']) {
  3. $ Ip = $ _ SERVER ['http _ CLIENT_IP ']; // PHP obtains the IP address
  4. } Elseif ($ _ SERVER ['http _ X_FORWARDED_FOR ']) {
  5. $ Ip = $ _ SERVER ['http _ X_FORWARDED_FOR '];
  6. } Else {
  7. $ Ip = $ _ SERVER ['remote _ ADDR ']; // PHP obtains the IP address
  8. }
  9. }

Example 2: The code is as follows:

  1. /*
  2. Mktime: 2012/9/9
  3. */
  4. // Obtain the user's real IP address
  5. Function get_client_ip (){
  6. If (getenv ("HTTP_CLIENT_IP") & strcasecmp (getenv ("HTTP_CLIENT_IP"), "unknown "))
  7. $ Ip = getenv ("HTTP_CLIENT_IP ");
  8. Else
  9. If (getenv ("HTTP_X_FORWARDED_FOR") & strcasecmp (getenv ("HTTP_X_FORWARDED_FOR"), "unknown "))
  10. $ Ip = getenv ("HTTP_X_FORWARDED_FOR ");
  11. Else
  12. If (getenv ("REMOTE_ADDR") & strcasecmp (getenv ("REMOTE_ADDR"), "unknown "))
  13. $ Ip = getenv ("REMOTE_ADDR ");
  14. Else
  15. If (isset ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR '] & strcasecmp ($ _ SERVER ['remote _ ADDR'], "unknown "))
  16. $ Ip = $ _ SERVER ['remote _ ADDR '];
  17. Else
  18. $ Ip = "unknown ";
  19. Return ($ ip );
  20. }
  21. Echo $ ip = get_client_ip (); // This is your ip address.
  22. ?>

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.