save to codehub

This commit is contained in:
vedant-chavan
2024-08-09 17:11:41 +05:30
commit 20f55281ef
412 changed files with 74718 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?php
use GeoIp2\Database\Reader;
function getCountryTimeZone($userSelectedCountry)
{
// Path to the GeoIP2 database file
$databasePath = storage_path('app/GeoLite2-Country.mmdb'); // Replace with the path to your downloaded database file
// Initialize the GeoIP2 reader
$reader = new Reader($databasePath);
try {
// Look up the country for the user's selected IP address or country code
$record = $reader->country($userSelectedCountry);
// Get the time zone from the country data
$timeZone = $record->location->timeZone;
return $timeZone;
} catch (\Exception $e) {
// Handle exceptions if the country code or IP address is not found
return 'UTC'; // Default to UTC if not found
}
}