Home Backend Development PHP Tutorial php中获取远程客户端的真实ip地址的方法_php技巧

php中获取远程客户端的真实ip地址的方法_php技巧

May 17, 2016 am 09:16 AM
client

(1).REMOTE_ADDR:浏览当前页面的用户计算机的ip地址

(2).HTTP_X_FORWARDED_FOR: 浏览当前页面的用户计算机的网关

(3).HTTP_CLIENT_IP:客户端的ip

在PHP 中使用 $_SERVER["REMOTE_ADDR"] 来取得客户端的 IP 地址,但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的 IP 地址,而不是真正的客户端 IP 地址。要想透过代理服务器取得客户端的真实 IP 地址,就要使用 $_SERVER["HTTP_X_FORWARDED_FOR"] 来读取。

不过要注意的事,并不是每个代理服务器都能用 $_SERVER["HTTP_X_FORWARDED_FOR"] 来读取客户端的真实 IP,有些用此方法读取到的仍然是代理服务器的 IP。

还有一点需要注意的是:如果客户端没有通过代理服务器来访问,那么用$_SERVER["HTTP_X_FORWARDED_FOR"] 取到的值将是空的。

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VMware Horizon Client cannot be opened [Fix] VMware Horizon Client cannot be opened [Fix] Feb 19, 2024 pm 11:21 PM

VMware Horizon Client cannot be opened [Fix]

VMware Horizon client freezes or stalls while connecting [Fix] VMware Horizon client freezes or stalls while connecting [Fix] Mar 03, 2024 am 09:37 AM

VMware Horizon client freezes or stalls while connecting [Fix]

PHP MQTT Client Development Guide PHP MQTT Client Development Guide Mar 27, 2024 am 09:21 AM

PHP MQTT Client Development Guide

What is the mobile client What is the mobile client Aug 16, 2023 pm 01:40 PM

What is the mobile client

How to write an FTP client in PHP How to write an FTP client in PHP Aug 01, 2023 pm 07:23 PM

How to write an FTP client in PHP

How to solve the problem that the Baidu Netdisk webpage cannot start the client? How to solve the problem that the Baidu Netdisk webpage cannot start the client? Mar 13, 2024 pm 05:00 PM

How to solve the problem that the Baidu Netdisk webpage cannot start the client?

How to remove the shield logo above the Win11 client? How to remove the shield logo above the Win11 client? Jan 05, 2024 am 11:21 AM

How to remove the shield logo above the Win11 client?

win11 client and server do not support commonly used ssl win11 client and server do not support commonly used ssl Dec 29, 2023 pm 02:09 PM

win11 client and server do not support commonly used ssl

See all articles