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 first 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 the user’s GEO Location using his IP address. Now just take it further to get the 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 the user through IP address.

Example.php

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

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

Recommended Posts For You

About Manish Kumar

I am PHP web developer and blogger.

View all posts by Manish Kumar

Leave a Comment

Your email address will not be published. Required fields are marked *