Introduction to the method of obtaining the real IP of the real client in PHP

高洛峰
Release: 2023-03-06 20:28:01
Original
1195 people have browsed it

REMOTE_ADDR is the IP when your client "handshakes" with your server. If an "anonymous proxy" is used, REMOTE_ADDR will display the IP of the proxy server.

HTTP_CLIENT_IP is the HTTP header sent by the proxy server. If it is a "super anonymous proxy", a value of none is returned. Likewise, REMOTE_ADDR will be replaced with the IP of this proxy server.

$_SERVER['REMOTE_ADDR']; //Accessing end (may be user, may be proxy) IP

$_SERVER['HTTP_CLIENT_IP']; //Agent end ( It may exist and can be forged)

$_SERVER['HTTP_X_FORWARDED_FOR']; //Which IP the user is using as a proxy (It may exist and it can also be forged)

The difference between the three values ​​is as follows:

1. When no proxy server is used:

REMOTE_ADDR = Your IP

HTTP_VIA = No value or not displayed

HTTP_X_FORWARDED_FOR = No value or not displayed

2. When using a transparent proxy server: Transparent Proxies

REMOTE_ADDR = The last proxy server IP

HTTP_VIA = Proxy server IP

HTTP_X_FORWARDED_FOR = your real 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.

This type of proxy server still forwards your information to your visitor, which cannot achieve the purpose of hiding your true identity.

3. When using ordinary anonymous proxy servers: Anonymous Proxies

REMOTE_ADDR = Last proxy server IP

HTTP_VIA = Proxy server IP

HTTP_X_FORWARDED_FOR = 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.

Hides your real IP, but reveals to the target audience that you are using a proxy server to access them.

4. The use of deceptive proxy servers: Distorting Proxies

REMOTE_ADDR = Proxy server IP

HTTP_VIA = Proxy server IP

HTTP_X_FORWARDED_FOR = 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. When using a high-anonymity proxy server: High Anonymity Proxies (Elite proxies)

REMOTE_ADDR = Proxy server IP

HTTP_VIA = No value or no display

HTTP_X_FORWARDED_FOR = No value or not displayed. 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.

Completely replaces all your information with the proxy server's information, just like you are using that proxy server to directly access the object.

//获取用户IP
$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);
Copy after login

The above is the detailed content of Introduction to the method of obtaining the real IP of the real client in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!