Home  >  Article  >  Backend Development  >  Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR php

Use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR php

WBOY
WBOYOriginal
2016-08-08 09:21:521192browse

Original URL: http://qq398705749.iteye.com/blog/963818

Usage of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in php
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.HTTP_CLIENT_IP: client's ip (This attribute has been verified as a pseudo attribute and does not actually exist, please do not misrepresent it)
Use $_SERVER["REMOTE_ADDR in PHP "] 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 client's real IP address through a proxy server, use $_SERVER["HTTP_X_FORWARDED_FOR"] to read.
However, something to note is 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 that if the client does not access through a proxy server, the value obtained with $_SERVER["HTTP_X_FORWARDED_FOR"] will be empty.
if ($_SERVER['HTTP_X_FORWARDED_FOR'] && preg_match('/^([0-9]{1,3}.){3}[0-9]{1,3}$/',$_SERVER ['Http_x_Forwardeded_For'])) {
$ onlineip = $ _Server ['http_x_Forwardeded_For']; ^([0-9] {1, 3}.){3}[0-9]{1,3}$/',$_SERVER['HTTP_CLIENT_IP'])) {
             $onlineip = $_SERVER['HTTP_CLIENT_IP'];
The difference between the three attributes of obtaining the user's IP address (HTTP_X_FORWARDED_FOR, HTTP_VIA, REMOTE_ADDR)
1. Without using a proxy server:
REMOTE_ADDR = your IP
HTTP_VIA = No value or not displayed
HTTP_X_FORWARDED_FOR = No value or not displayed
2. The situation of using transparent proxy server: Transparent Proxies
REMOTE_ADDR = Last proxy server IP
HTTP_VIA = Proxy server IP
HTTP_X_F ORWARDED_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. The situation of 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 The values ​​are 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
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 As follows: 203.98.182.163, 203.98.182.163, 203.129.72.215.
Tell the person you are visiting 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 high-anonymity proxy servers: High Anonymity Proxies (Elite proxies)
REMOTE_ADDR = Proxy server IP
HTTP_VIA = No value or no display
HTTP_X_FORWARDED_FOR = No value or no display, 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.
Completely replaces all your information with the proxy server's information, just like you are using that proxy server to directly access the object.
The above introduces the use of HTTP_X_FORWARDED_FOR and REMOTE_ADDR in php, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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