How to block access from certain countries on the blog
Hello everyone, on this occasion I will share how to block access from certain countries on the blog with Cloudflare.
just yesterday i blocked access from Vietnamese country on this blog with a feature from cloudflare, with some reasons below.
the reason I blocked access from Vietnamese, because many people from there copied my article and republished it without permission.
apart from that, even my blog was reported to DMCA as the owner of the original content, even
my blog has been click bombed twice in Vietnamese, this is not an accusation because this can be seen on the Adsense dashboard from which country clicked on our ad.
Apart from the reasons above, I also often receive spam emails from people in the country asking for the template that I use, even though it is clear that this is a premium template.
with several reasons and sufficient considerations, I have decided to block that country from accessing this blog.
for those of you who are looking for a way to make your site accessible only in certain countries or want to block access from certain countries, let's see the method below.
before starting make sure you have a TLD domain
,what's our mean is .com .id .co.id
etc not .blogspot.com
, and also make sure your domain has pointed to the name server from cloudflare and activated the cloud proxy.. you can read here...
How to point a domain nameserver to cloudflare
Step 1: Please visit
https://dash.cloudflare.com
And follow the image instructions below.
Step 2: Select the Firewall menu
Then go Firewall Rules
> Create a Firewall rule.
Step 3 In the Rule name, fill it with whatever is free, in the Field select Country, in Operator select equals, in Value select the name of the country
you want to block. if you have clicked the blue button Deploy or save
Step 4: Now you have successfully blocked access from that country, now the weakness is that this country can still access our blog if you use a VPN. vpn only change ip not with timezone on their device so here we can also block timezone of that country with below javascript.
Blocking Time Zones With Javascript
Please go to blogger
> themes
> edit html
copy the css below and place it above the code ]]></b:skin>
or </style>
/* timezone detector by Techno Praveen */ @-webkit-keyframes slide-down{0%{opacity:0;-webkit-transform:translateY(-100%)}100%{opacity:1;-webkit-transform:translateY(0)}}@keyframes slide-down{0%{opacity:0;transform:translateY(-100%)}100%{opacity:1;transform:translateY(0)}} .tp-dtc{width:100%;height:100%;position:fixed;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.5);z-index:99999;-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px);display:none} .tp-dtc-knt{width:100%;max-width:500px;position:relative;background:#fefefe;border-radius:10px;border:1px solid #eee;color:#262d3d;text-align:center;padding:35px;top:150px;margin:20px auto;box-shadow:0 10px 20px rgba(0,0,0,0.2);-webkit-animation:slide-down 2s ease-out;animation:slide-down 2s ease-out} .tp-dtc-knt h2{margin-top:15px;font-size:17px} .tp-dtc-knt svg.st1{fill:#e00000;width:50px;height:50px}
Further copy the below html and place it above the code </footer
>div class="tp-dtc"< >div class='tp-dtc-knt'< >svg class='st1' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'<>path d='M7.775 0a1.8 1.8 0 0 0-1.273.527L.528 6.503A1.8 1.8 0 0 0 0 7.775v8.45c0 .478.19.936.528 1.274l5.974 5.974A1.8 1.8 0 0 0 7.775 24h8.45a1.8 1.8 0 0 0 1.273-.527l5.975-5.974A1.8 1.8 0 0 0 24 16.225v-8.45a1.8 1.8 0 0 0-.527-1.272L17.498.527A1.8 1.8 0 0 0 16.225 0zm4.427 3c1.02 0 .958 1.108.958 1.108v6.784s-.009.218.16.218c.188 0 .175-.226.175-.226l-.002-5.63s-.05-.986.959-.986c1.01 0 .97.983.97.983v7.621s.014.158.141.158c.127 0 .944-2.122.944-2.122s.451-1.497 2.576-1.1c.038.008-.167.688-.167.688l-2.283 6.556S15.69 20.7 11.714 20.7c-5.044 0-4.808-5.407-4.814-5.405V7.562s-.016-.99.897-.99c.858 0 .849.99.849.99l.007 3.583s-.004.172.167.172c.16 0 .141-.172.141-.172l.01-5.926s-.055-1.162.966-1.162c1.04 0 .983 1.142.983 1.142v5.611s-.005.204.152.204c.168 0 .154-.206.154-.206l.01-6.693S11.18 3 12.202 3Z'/<>/svg< >h2 data-en='Access Blocked'<Access Blocked>/h2< >p data-en='this site is not available in your country.'<This site is not available in your country.>/p< >a href='javascript:;' id='tptj'glt;translate to Vietnam>/a< >/div<
And lastly copy and put below javascript above the code </body> or like <!--</body>-- ></body>
>script</*>![CDATA[*/ /* timezone detector by Techno Praveen */ function detectCntry() { var detec = (Intl.DateTimeFormat().resolvedOptions().timeZone); // get the timezone on the device var blkcnry = 'Asia/Calcutta'; // zone string the time of the country to be blocked if(detec === blkcnry){ // if the timezone on the device is the same as Asia/Calcutta then run the function below document.querySelector('.tp-dtc').style.display = 'block'; // displays a country notification pop up not available in your country } // js translation you can remove this if not needed document.querySelector('#tptj').addEventListener('click', wctj); function wctj() { var hdw = document.querySelector('.wc-dtc-knt h2'); var hda = hdw.getAttribute('data-en'); hdw.innerHTML = hda; var prg = document.querySelector('.tp-dtc-knt p'); var pra = prg.getAttribute('data-en'); prg.innerHTML = pra; document.querySelector('#tptj').style.display = 'none'; } } detectCntry(); /*]]<*/>/script<
Note that what I marked Asia/Calcutta is the time zone string of India, for those of you who want to block other countries but don't know how to write the time zone string, you can follow the method below.
Take your smartphone > go to settings > other settings > date & time > select the time zone, please change to the time zone of the country you want to block, if you have visited the check time zone link with your smartphone then you will see it later.
ok, so that's all the ways to block access from certain countries on the blog that I can share this time, I hope
This is useful and thank you for visiting.