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:
I am trying to set user timezone based on his/her country. I am getting user country from his IP address, But I need timezone region of that country like('Asia/Calcutta') to check whether DST is on in that country. Can anyone please provide me some suitable solution in PHP?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With