Home > Backend Development > PHP Tutorial > Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in PHP_PHP Tutorial

Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in PHP_PHP Tutorial

WBOY
Release: 2016-07-20 11:15:59
Original
1127 people have browsed it

Reference source: http://qq398705749.iteye.com/blog/963818

1.REMOTE_ADDR: The IP address of the user’s computer browsing the current page
2.HTTP_X_FORWARDED_FOR: The gateway of the user’s computer browsing the current page
3.: The client’s ip

in PHP Use to obtain the client's IP address.

But if the client uses a proxy server to access, what is obtained is the IP address of the proxy server, not the real client IP address. To obtain the real IP address of the client through the proxy server, use to read it.

However, please note that not every proxy server can use $_SERVER["HTTP_X_FORWARDED_FOR"] to read the real IP of the client. Some of the IPs read by this method are still the IP of the proxy server.

Another thing to note is: , then the value obtained with $_SERVER["HTTP_X_FORWARDED_FOR"] will be empty.

Php codeUse of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in PHP_PHP Tutorial 🎜>Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in PHP_PHP Tutorial] && preg_match(Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in PHP_PHP Tutorial'/^([0-9]{1,3}.){3}[0-9]{1,3}$/' ,$_SERVER['HTTP_X_FORWARDED_FOR'])) {   $onlineip = $_SERVER['HTTP_X_FOWRWARDED_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 in obtaining the three attributes of the user's IP address (HTTP_X_FORWARDED_FOR, HTTP_VIA, REMOTE_ADDR): 1. The case of not using a proxy server
  • :
  • = Your IP
    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']; 
    } 
    
    Copy after login


    = No value or not displayed

    = No value or not displayed

    2. When using a transparent proxy server: Transparent Proxies
    = Last proxy server IP
    = Proxy server IP

    = Your real IP, after When there are multiple proxy servers, this value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.

    This type of proxy server still forwards your information to the person you visit, and cannot achieve the purpose of hiding your true identity. 3. Situation of using ordinary anonymous proxy server
    : Anonymous Proxies = last proxy server IP
    = Proxy server IP

    = Proxy server IP. When passing through multiple proxy servers, this value is similar to the following: 203.98 .182.163, 203.98.182.163, 203.129.72.215.

    Hide your real IP, but reveal to your visitors that you are using a proxy server to access them. 4. The use of deceptive proxy servers
    : Distorting Proxies = proxy server IP
    = Proxy server IP

    = Random IP. When passing through multiple proxy servers, this value is similar to the following: 203.98.182.163 , 203.98.182.163, 203.129.72.215.

    Tell the visitor that you are using a proxy server, but make up a fake random IP instead of your real IP to trick it. 5. Situation of using high anonymity proxy server
    : High Anonymity Proxies (Elite proxies)
    = Proxy server IP
    = No value or not displayed
    = No value or Not displayed, when passing through multiple proxy servers, the value is similar to the following: 203.98.182.163, 203.98.182.163, 203.129.72.215.

    Completely replaces all your information with the proxy server's information, just like you are using that proxy server to directly access the object.​
  • www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440138.htmlTechArticleReference source: http://qq398705749.iteye.com/blog/963818 1. REMOTE_ADDR: Browse the current page The IP address of the user’s computer 2. HTTP_X_FORWARDED_FOR: The IP address of the user’s computer browsing the current page...
    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template