phplaraveltimezonegeoipphp-8.1

PHP 8.1 - Laravel - Geoip find timezone by country and region


I want to find the timezone with the country and region using

geoip_time_zone_by_country_and_region()

but seems it needs geoip ext to be installed which is not supported anymore and seems geoip2 just works with IP but I want to get the timezone by country and region(state) name is there any solution? I'm using Laravel 9 and PHP 8.1


Solution

  • 2 choices

    Get free versions of maxmind geoip (Geolite DB) and use them . Cumbersome for just the zone

    Use javascript https://www.geeksforgeeks.org/how-to-set-timezone-offset-using-javascript/ ..offset example

    Or if you want the actual zone text:

    var justforRefTz ; justforRefTz = Intl.DateTimeFormat().resolvedOptions().timeZone;