/    Sign up×
Community /Pin to ProfileBookmark

How to code country blocking of a website

Hello.

I intend to block visitors of my future website from Internet users of a particulat country. What is the best way of coding that?

I am looking for a free way, if possible – without using any commercial product.

(I know that the people from the particular country could use a proxy or a vpn thing, but there is nothing I can do about that I guess.)

Thank you.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NachfolgerMay 22.2020 — I would strongly recommend using CloudFlare to complete this task. It will block the visitor before they even reach your website, which saves you resources. I haven't fact checked this, but I think the firewall is free to even the first tier members.

In addition to the country lock, you also get performance boosts. It's a win-win.
Copy linkTweet thisAlerts:
@codewitchauthorMay 22.2020 — I am not interested in products, neither commercial or nor free.

I am interested in a way how to code that. I like to challenge myself with new challenges.

@Nachfolger: please stop replying to the threads that I start with these "CloudFlare suggestions". Thank you.
Copy linkTweet thisAlerts:
@NachfolgerMay 23.2020 — @codewitch#1618725

To the best of my knowledge, this would be the first time I’ve recommended CF to you. Let alone one of the first times I’ve made the recommendation on this forum.

Regardless, if you think you’re more capable developer than a multi-billion dollar company with countless data centers globally, be my guest.

At the core, you need to determine if a user is from a certain country. You can use a IP address decoder, although I suspect you think you’re smart enough to write one yourself, I would recommend a API like ipinfo.com. Once you determine the users country, simply block them if they’re from a blacklisted country.

Conceptually, this is a very simple task to accomplish. It worries me that you aren’t able to begin developing this on your own without asking for a starting point. A capable developer doesn’t need to ask such simple questions.

Best of luck to you. 😆
Copy linkTweet thisAlerts:
@codewitchauthorMay 23.2020 — Hello Nachfolger.

You have recommended the CloudFlare to me before here: (post number eight)

https://www.webdeveloper.com/d/389836-is-there-a-law-about-cookies

Do you own the company? Hihi

I am not an experienced web developer.
Copy linkTweet thisAlerts:
@NachfolgerMay 23.2020 — @codewitch#1618728

> @codewitch#1618728 You have recommended the CloudFlare to me before here: (post number eight)
>
> [https://www.webdeveloper.com/d/389836-is-there-a-law-about-cookies](https://www.webdeveloper.com/d/389836-is-there-a-law-about-cookies)


Oh, I see. No, I don't own CloudFlare.

> @codewitch#1618728 I am not an experienced web developer.

This is exactly the reason I suggested using it in the first place.

I'll refrain from posting any further in this thread. It's clearly a waste of my time.
Copy linkTweet thisAlerts:
@anthony7nrMay 24.2020 — codewitch, I just wonder, how many countries do you want to welcome with their own details in interface?
Copy linkTweet thisAlerts:
@NogDogMay 24.2020 — The basic process is to select an IP address/location database (do some googling, there are a variety, some free, some not, different update periodicities, etc.), check the value of $_SERVER['REMOTE_ADDR'] against that database, and react accordingly.
Copy linkTweet thisAlerts:
@VITSUSAMay 26.2020 — @codewitch#1618717 CloudFlare is the best option for you.
Copy linkTweet thisAlerts:
@brijeshJun 11.2020 — I think codewitch is best.
×

Success!

Help @codewitch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...