获取用户IP地址php的明确方法 [英] definitive way to get user ip address php

查看:57
本文介绍了获取用户IP地址php的明确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
用于获取用户ip地址的功能

Possible Duplicate:
Function to get user ip address

<?PHP

$ipaddress = $_SERVER["REMOTE_ADDR"];

echo "Your IP is $ipaddress!";

?>

有人告诉我这种获取ip地址的方式存在一些问题,例如能够欺骗用户.有没有更好的方法来收集IP地址?在寻找获得IP地址的更好方法的教程?

I was told this way of getting ip address has issues such as being able to fool. Is there a better way to gather ip address? looking for tutorials of better way to get ip address?

推荐答案

$_SERVER['REMOTE_ADDR']是您将获得的唯一可靠的IP地址-它直接从TCP堆栈中提取,并且是建立当前连接的地方.这意味着,如果用户通过代理进行连接,则将获得代理的地址,而不是用户的地址.

$_SERVER['REMOTE_ADDR'] is the only reliable IP address you'll get - it's extracted directly from the TCP stack and is where the current connection was established from. This means if the user is connecting via a proxy, you'll get the proxy's address, not the user's.

其他任何基于标头的都不可靠,因为HTTP标头很难伪造.只要您不信任它,就可以使用他们提供的信息.

Any of the other header-based ones are unreliable, as HTTP headers are trivial to forge. You can use the information from them, if you'd like, as long as you don't TRUST it.

这篇关于获取用户IP地址php的明确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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