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

从客户端的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..

有没有办法检测到我的客户端的IP地址然后使用它来跟踪他的时区.. iam当前 将此代码块与API一起使用: p>

 函数getIpAddress(){
 return(空($ _ SERVER ['HTTP_CLIENT_IP'])?(空($ _ 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']; 
  code>  pre> \  n 
 

$ ip返回122.54.230.162。 但仍然说我的问题是 p>

 消息:未定义的索引:timezone 
  code>  pre> 
 
 

在服务器上测试它将 显示此错误,当它在本地时没问题。 i需要帮助 p>

最好的问候.. p> div>

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.