使用PHP获取用户真实的IP地址 [英] Getting Users Real IP address using PHP
本文介绍了使用PHP获取用户真实的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使他们使用像hidemyass.com这样的代理网站,我想从我网站上的用户那里获得真实的IP地址
I want to get the real IP address from users going on my site even if they use a proxy website like hidemyass.com
这是我的代码和认为它有效,但我测试了它并没有
This is the code I have and thought it worked but I tested it and it doesn't
<?php
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>
我认为这段代码可行,但代理仍然绕过它。
I thought this code would work but proxy still bypass it.
提前致谢。
推荐答案
如果代理人不想告诉你,没有保证获得真实IP地址的方法它(以及任何真正的匿名代理不会)。
There is no guaranteed way to get a "real" IP address, if the proxy doesn't want to tell you about it (and any true anonymous proxy won't).
这篇关于使用PHP获取用户真实的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文