0

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..

Vainglory07
  • 5,073
  • 10
  • 43
  • 77

1 Answers1

3

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.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251