Search code examples
cloudflareregioncountry

Block users by US state


How could I block access to my website from users whose IP belong to particular US states? I'm using CloudFlare. It is easy to block the whole country, but only some states have to be blocked.


Solution

  • I have used MaxMind with great success: https://www.maxmind.com/en/geoip2-precision-services

    When you start a new session for a user, you get their IP and hit the above API. It will reply with data and from there you can decide to keep the user session or dump it.

    MaxMind is an international database so there is no state field. They call it Subdivisions if I remember correctly.