Getting timezone via IP Getting timezone via IP json json

Getting timezone via IP


ip-api.com responds with data based on the IP from which the request came. If you're in the Philippines and are accessing the website, you'll see information about yourself. If your server is in America and is requesting from the site, it'll see information about itself.

If you want your server to retrieve information about the client that's visiting it, you'll have to pass along the visiting client's IP. According to the documentation, you append it to the URL:

file_get_contents('http://ip-api.com/json/' . $_SERVER['REMOTE_ADDR'])


http://ip-api.com/json/ is not working anymore (at least for me)

I ended up using this instead:

curl -s http://geoip.ubuntu.com/lookup | grep -oP '(?<=<TimeZone>)(.*)(?=</TimeZone>)'