PHP implementation to obtain the real IP of the real client
This article mainly introduces the method of PHP to obtain the real IP of the real client (REMOTE_ADDR, HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR), which has a good reference value. Let’s take a look with the editor below
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']; //Accessor (may be a user, may be a proxy) IP
$_SERVER['HTTP_CLIENT_IP']; //Agent side (may exist, can be forged)
##$_SERVER['HTTP_X_FORWARDED_FOR'] ; //Which IP the user is using as a proxy (may exist or can be forged)
The difference between the three values is as follows:
1. When no proxy server is used:
REMOTE_ADDR = Your IPHTTP_VIA = No value or no displayHTTP_X_FORWARDED_FOR = No value or not displayed2. When using a transparent proxy server: Transparent Proxies
REMOTE_ADDR = The last proxy server IP HTTP_VIA = Proxy server IPHTTP_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 IPHTTP_VIA = Proxy server IPHTTP_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 IPHTTP_VIA = Proxy server IPHTTP_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 IPHTTP_VIA = No value Or not displayed 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);
Learn how to obtain clientip in php
PHP is based on socket to implement the client and server communication function method
PHP programming to implement TCP server and ClientDetailed explanation of functional steps
The above is the detailed content of PHP implementation to obtain the real IP of the real client. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
