dqd2800 2016-06-15 04:58
浏览 51
已采纳

为什么我的PHP IP查询会在Chrome for Mobile上返回Google IP地址

I have the following script in a php file to get the user's IP..

<?php
function GetIP()
{
    foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $keyip)
    {
        if (array_key_exists($keyip, $_SERVER) === true)
        {
            foreach (array_map('trim', explode(',', $_SERVER[$keyip])) as $uip)
            {
                if (filter_var($uip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
                {
                    return $uip;
                }
            }
        }
    }
}
$ip = GetIP();
echo $ip;
?>

and it works fine when I run it from my computer or MY phone (using Chrome browser), returning my correct IP address in Argentina. However, when I run it from both of my brother's phone using the Chrome browser it is giving me 66.249.85.30 which seems to be a Google proxy (hostname: google-proxy-66-249-85-30.google.com). When I use the regular internet browser on the phones it gives the correct IP address.

When I do an online search to get my IP address using the Chrome browser on my brothers' phones, it (whatismyip.com) returns the correct IP address and not the Google IP, so it has to be possible.

Does anyone know why it is doing this and what can be done to get the real IP address?

  • 写回答

1条回答 默认 最新

  • dongpi9480 2016-06-15 07:03
    关注

    It looks like this could be the Data Compression Proxy used by Chrome mobile browser when the Data Saver feature is turned on.

    The core optimizations that allow us to reduce overall data usage are performed by Google servers. When Data Saver is enabled, Chrome opens a connection between your phone and one of the optimization servers running in Google's datacenters and relays all non-encrypted HTTP requests over this connection.

    To check if this feature is enabled on the user's browser, you can check if the save-data HTTP Header exists and is set to 'on'. You can obtain their 'real' IP using the X-Forwarded-For header in this case - the header information can be manipulate so not guaranteed.

    It looks like your code is looking for that header, but it could be overcomplicating things and might be returning the proxy IP before the real. I haven't got a PHP server set up to test but you could do a dump of the $_SERVER variable or output some information within the loop to see what is happening.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用