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.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Check out the Maxmind GeoLite2 database. It contains details about the continent/country/city and lat/lon for most IP addresses including the time_zone as you can see below.
I describe how to compile the PHP extension, and how to use the mmdb databases in PHP here:
Intro to Maxmind GeoLite2 with Kohana PHP
It's not straight forward but I get the time including daylight saving offset from 2 api calls using jquery and php. All of it could be done in PHP quite easily with a bit of adaptation. I'm sure this could be laid out differently too but I just grabbed it from existing code which suited my needs at the time.
Jquery/php:
locate.php
Register for a free key here: http://ipinfodb.com/register.php (no limits but queued if more than 1 request per second)
Here's an example using a location API that maps IP address to timezone, e.g. send a request to
https://ipapi.co/<IP-Address>/timezone/
& get back timezone for that IP address.PHP Code
Accuracy is not 100% as others have said.