My server is hosted in Europe but my client is in South Asia. I want to find out my client's timezone without client-side scripting in NodeJS - ExpressJS. Is finding timezone using IP a correct approach?
Asked
Active
Viewed 520 times
0
-
try to use Time Zone API from Google – Aliaksandr Pitkevich Jun 10 '21 at 14:54
-
If you can't touch the client code at all and the client isn't already sending something else that would help, then I think using the IP address would make sense. I'd also go with a third-party API like the above comment mentions, but just make sure you're using the *correct* IP Address. Reverse proxies will alter the incoming IP Address as noted in this other SO question and answer (also note the other answers and comments so you're aware of why and when changes occur): https://stackoverflow.com/a/14631683/3781737 – user3781737 Jun 10 '21 at 16:12
-
Your deployment architecture might be able to help you with this. For example, if you were hosting your server on AWS, you could put it behind a CloudFront distribution. If you did this, you may be able to infer your client's location from the `CloudFront-Viewer-Country` and `CloudFront-Viewer-Country-Region` headers on the incoming request (assuming they weren't spoofing their location). You could then derive the timezone for this location in your server's code: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-cloudfront-headers.html – 8bitjunkie Jun 11 '21 at 01:54