How to get the Time Zone from IP address in PHP?
Using below PHP script, we can get the time zone based on IP address:
$ip = '192.168.11.121'; # any working IP address
$ipContent = file_get_contents('http://ip-api.com/json/' . $ip);
$ipJsonInfo = json_decode($ipContent);
$timeZone = $ipJsonInfo->timezone;
#Print the $timeZone
echo $timeZone;
Here, also can set this time zone as default using below function:
date_default_timezone_set($timeZone);
Comments
Post a Comment