My Programming Tutorials

My Programming Tutorials

Server & Client Timezone difference problem? use this trick.

Last updated on by , no comments

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!

Author Info

Paritosh Pandey

He loves Technology

Advertisement

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.