Cloudflare IP Geolocation替代方案? 在Javascript或PHP?

What I'm looking to do is to display different data on the page dependant on what country the user is visiting from.

eg. if visitor is from UK display X else display Y.

CloudFlare offers a nice feature where they look up the geolocation of the user based on their IP however we can't use that on our website for other reasons. https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-CloudFlare-IP-Geolocation-do-[1]

Does anyone know of any ways of how this could be done?

  • HTML5 geolocation isn't an option as this gives the user a choice to allow sharing of location, we don't want the user to have a choice.

  • Yes I am aware that users could easily bypass this using a proxy or other means but we're trying to reduce manual checks on users location as much as possible.

Any advice or alternatives to do what I'm trying to do would be appreciated.

Yes. You can do it thru various IP Geolocation API services available. Here is a small list.

https://ipgeolocation.io -- 50,000 requests per month for free.

https://ipstack.com -- 10000 requests per month for free

https://ip2location.com -- provides a free lookup database only. API is paid

https://maxmind.com -- provides a free Geolite2 database only. API is paid.

https://ipinfo.io -- Used to provide free quota but no information of free plan is on their site currently.