doulubashang6936 2012-12-12 05:04
浏览 107
已采纳

从客户端的IP地址检测时区

is there a way to detect to IP Address of my client then use this to track his timezone.. iam currently using this block of code together with an API:

    function getIpAddress() {
    return (empty($_SERVER['HTTP_CLIENT_IP'])?(empty($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['REMOTE_ADDR']:$_SERVER['HTTP_X_FORWARDED_FOR']):$_SERVER['HTTP_CLIENT_IP']);
}

    ini_set("allow_url_fopen",1);
    $getfunc= 'getIpAddress';
    $getfunc= 'getIpAddress'; 
    $json   = file_get_contents('http://smart-ip.net/geoip-json/'.$ip);
    $ipData = json_decode( $json, true);
    $ipadd   = $ipData['host'];
    $geotz  = $ipData['timezone'];
    $geotzd = 'Passed';
    $cntry  = $ipData['countryName'];

the $ip returns 122.54.230.162. but still sayin that my problem is

    Message: Undefined index: timezone

testing it on the server will show this error while it is okay on local.. i need help

best regards..

  • 写回答

1条回答 默认 最新

  • douzhang5984 2012-12-12 05:22
    关注

    There are various ways of guessing the timezone. Using a service like in your question is one, although that code looks to me like it gets the timezone of the local computer, but I could be wrong. In any case, it doesn't seem reliable.

    Another way is the jstimezonedetect javascript library.

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

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题