dongshanxiao7328 2017-10-24 13:33
浏览 514
已采纳

PHP - 按国家/地区名称获取时区

I want to get the time zone abbreviation of visitor and for this purpose i am using the below code:

$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
$visitor_country_code = $details->country . 'T';

From this i got the first two letters of country name and concatenated 'T'.But this is working only for few countries.I tested it by changing proxy and it worked for Pakistan and then i tried for USA and it gave me error

DateTimeZone::__construct(): Unknown or bad timezone (AEDT)

Can someone help me to get the country code of all countries?

  • 写回答

1条回答 默认 最新

  • dpqvwgr74759 2017-10-24 14:04
    关注

    You can use https://freegeoip.net/json/[IP address] to get all the information you want.

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

报告相同问题?