dongma7725 2014-01-10 18:04
浏览 80
已采纳

使用代理获取客户端IP地址 - PHP5.4.4-14 + APACHE 2.2.22-13 + Debian 7 + HTTPS

I tried every codes and read all posts with this topic, but none resolved my problem.

The code doesnt get the real IP when the browser option "use proxy for intranet sites" is on.
It shows me the PROXY IP...

Code:

function get_ip_address()
{
    $aa = array ( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', // 'HTTP_HOST', 'REMOTE_ADDR');

    foreach ($aa as $key) {
        if (array_key_exists($key, $_SERVER) === true) {
            foreach (explode(',', $_SERVER[$key]) as $ip) {
                if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
                    return $ip;
                }
            }
        }
    }
}
#endfunc

echo get_ip_address();
  • 写回答

2条回答 默认 最新

  • dongyounai6281 2014-01-10 18:50
    关注

    Well, that's the purpose of proxies. You cannot reliably obtain the IP address of your user and, even if you could, do you mean their WAN address? Or one of any number of LAN addresses? It's an intractible problem in the general case.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码