How to limit web site access to USA or North America only

This is a corporate site so Private. We want to limit access by IP address to USA/Canada or North America. Based on IP range, would allow user/pwd to get in otherwise -‘no access’. Just trying to limit hack exposure from anything overseas.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Anybody who could get past your password security could easily get past any IP filtering security (and it may even be seen as a challenge, thus increasing the risk of overseas hacking). I think the premise of your question is flawed.

Method 2

If your main aim is to prevent unauthorized access to your website by IP… that will never ever work. Its so easy to bypass that. a user/pwd would be a more secure option.

To answer your question, if you have certain features or a complete website block that you want to do, this is a tutorial:

Method 3

There are various libraries that will do geocoding of IP address. The one I’ve used is GeoIP, which has a free version.

Note that IP addresses can be spoofable, so anyone wanting to get around your check will be able to. Any serious hackers won’t be very deterred.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x