php:geting ip addres [英] php: geting ip addres

查看:140
本文介绍了php:geting ip addres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个访问者的IP地址。
你能告诉我我应该使用 $ _ SERVER [] 的哪个元素?

i want to get an ip addres of visitors. could you tell me what element of $_SERVER[] i should use?

$_SERVER['HTTP_CLIENT_IP'];
$_SERVER['HTTP_X_FORWARDED_FOR'];
or
$_SERVER['REMOTE_ADDR'];

谢谢

更新:

如果您的客户端通过Proxy Server连接到Internet,则PHP中的$ _SERVER ['REMOTE_ADDR']只返回代理服务器的IP地址不是客户端的机器。有额外的服务器变量可用于确定PHP中客户端机器的确切IP地址,它们是HTTP_CLIENT_IP和HTTP_X_FORWARDED_FOR。

If your client is connected to the Internet through Proxy Server then $_SERVER['REMOTE_ADDR'] in PHP just returns the the IP address of the proxy server not of the client’s machine.There are extra Server variable which might be available to determine the exact IP address of the client’s machine in PHP, they are HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR.

推荐答案

$ _ SERVER ['REMOTE_ADDR'];

根据 PHP文档
用户的IP地址正在查看当前页面。

According to the PHP documentation: The IP address from which the user is viewing the current page.

这是连接到服务器的IP(通过服务器报告)。

其他值是由客户设置。

This is the IP that is connected to your server (reported by your server).
The other values are set by the client.

HTTP_X_FORWARDED_FOR 是非标准头(因此是x前缀),设置通过某些代理服务器。大型代理服务器供应商试图帮助ISP识别滥用的IP地址;它包含一个包含所有转发IP的列表。

The HTTP_X_FORWARDED_FOR is a non-standard header (hence the x-prefix), set by certain proxy-servers. It is an attempt by the big proxy server vendors to help ISPs identify abusive IP addresses; it contains a list with all forwarded-for IPs.

我不知道 HTTP_CLIENT_IP 标题的来源

这篇关于php:geting ip addres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆