How to find timezone ID from IP address/country name 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.

Leave a Comment