Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Time Zone through IP Address in PHP [duplicate]

I want to get time zone through an IP Address in PHP. Actually, I have an application which will run at the client machine. I have the IP address of the client machine. But I am not able to get the time zone for each client machine.

like image 459
Devesh M Avatar asked Apr 13 '09 10:04

Devesh M


People also ask

How to get timezone from IP address in PHP?

Show activity on this post. $ip = "189.240. 194.147"; //$_SERVER['REMOTE_ADDR'] $ipInfo = file_get_contents('http://ip-api.com/json/' . $ip); $ipInfo = json_decode($ipInfo); $timezone = $ipInfo->timezone; date_default_timezone_set($timezone); echo date_default_timezone_get(); echo date('Y/m/d H:i:s');

How can I get current location from IP address in PHP?

PHP has an extension for that. From PHP.net: The GeoIP extension allows you to find the location of an IP address. City, State, Country, Longitude, Latitude, and other information as all, such as ISP and connection type can be obtained with the help of GeoIP.


1 Answers

$ip = "189.240.194.147";  //$_SERVER['REMOTE_ADDR'] $ipInfo = file_get_contents('http://ip-api.com/json/' . $ip); $ipInfo = json_decode($ipInfo); $timezone = $ipInfo->timezone; date_default_timezone_set($timezone); echo date_default_timezone_get(); echo date('Y/m/d H:i:s'); 

Sometime it won't work on local server so try on server.

Edit: This data is coming from ip-api.com, they're free to use as long as you don't exceed 45 requests per minute and not using commercially. See their TOS, not a long a page.

like image 144
Chandrika Shah Avatar answered Oct 02 '22 12:10

Chandrika Shah