How to find timezone ID from IP address/country name in PHP?

后端 未结 4 520
北荒
北荒 2020-12-02 01:40

Can anyone please tell me if there is any way available in PHP to fetch timezone region like(\'Asia/Calcutta\') from IP Address or country name?

Description:

<
4条回答
  •  青春惊慌失措
    2020-12-02 02:46

    Using IP Address

    Timezones follow sometimes quirky rules. IP geolocation is anything but precise (notwithstanding the claims of some vendors).

    Having said that, you can certainly find the city and country using a Geo IP product such as MaxMind's:

    http://www.maxmind.com/app/geolite

    which includes a PHP module

    http://www.maxmind.com/app/php

    You can then use the MaxMind APIs to try and estimate the user's timezone

    http://www.maxmind.com/app/faq#timezone

    Alternative

    If you want to rely on your user's clock rather than the IP address, jsTimezoneDetect works quite well (though it is not perfect).

    https://bitbucket.org/pellepim/jstimezonedetect/wiki/Home

    Summary

    Neither technique works perfectly in all cases. Be sure you allow your user to correct any auto-generated timezone suggestion.

提交回复
热议问题