First
Grab user’s IP address
Second
Use bellow codes to fetch the timezone of users using their IP Address.
$ip = "189.240.194.147"; // user's IP Address
$ipInfo = file_get_contents('http://ip-api.com/json/' . $ip);
$ipInfo = json_decode($ipInfo);
$timezone = $ipInfo->timezone;
Third
Now its time to set the timezone in your PHP based script. Everyone know php execution starts from index.php
file.
So we just need to set the timezone code in the starting line of index.php
file.
date_default_timezone_set($timezone);
Thats all! enjoy!
Please help us by showing your reaction
Leave a Reply