I recently built a website and I'm curious if there's a way to limit access to just people located in my city. Is this doable? Would it make a difference if I wanted to restrict it to just my state instead of my city?
5 Answers
Honestly, I’d reconsider this approach. While tools like Cloudflare can block by country, filtering by city or state gets tricky due to the inaccuracies of IP address data. You could end up blocking locals while outsiders gain access from other locations. I’d suggest thinking of a different strategy to manage access.
There are APIs out there that can help determine where requests are coming from, but they aren't reliable if users are using VPNs. You could ask users to enable location services in their browsers, but that's not a common practice for most sites.
If you’re serious about access restriction, implement a login or invite-only approach rather than relying solely on geo-filters. This way, you can better control who enters your site.
Yes, you can limit access based on IP addresses, which can generally point to a country, state, or even city. However, keep in mind that this method isn't foolproof; people can easily use VPNs to bypass these restrictions. It might work better for larger cities compared to smaller ones, so it really depends on your specific area.
The easiest method is to use Cloudflare, which allows you to set up rules for blocking access based on geographic location. Check out their documentation for step-by-step instructions on implementing this.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads