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条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号