Getting User TimeZone through IP Address in PHP

Many websites need to display the time of some event, which is local for the logging user. For this there needs to firstly get the time zone of that user. In this article, we will see the way to determine the time zone of the current user.

In my previous article Get IP Address and Geo Location of Login User, I have described the simplest way to get user’s GEO Location using his IP address. Now just taking it further to get user’s time zone.

Getting User TimeZone through IP Address in PHP

Getting Time Zone of User Through IP Address

Before using the below code, you need to get an API KEY for Google Maps Time Zone API , that you can get from Google developer console.

To get time zone using IP address, need to include “GoogleMapsTimeZone.php” file. This is the class file defining all the functionality implementation. You can find this class file code on Github.

Check below code “example.php” file, in which we are getting the timezone of user through IP address.

Example.php


Get that straight code on your website and show user time zone on the basis of IP address.

If you like this tutorial, please share with others. Thanks

Leave a Comment