I have googled for ages to reach my goal, but in vain.
I have a blogger blog for which I have purchased a custom domain.
Unfortunately, to the best of my knowledge, I dont think blogger supports php or .htaccess
or something like that.
I think it supports only basic things like html
, css
, javascript
, jquery
, ajax
.....Nothing from the server side is possible I guess (ie: php).
I want to block a particular country from visiting my website. Is there any way to do this using simple client side code?
I have googled for ages to reach my goal, but in vain.
I have a blogger blog for which I have purchased a custom domain.
Unfortunately, to the best of my knowledge, I dont think blogger supports php or .htaccess
or something like that.
I think it supports only basic things like html
, css
, javascript
, jquery
, ajax
.....Nothing from the server side is possible I guess (ie: php).
I want to block a particular country from visiting my website. Is there any way to do this using simple client side code?
Share Improve this question edited Jan 14, 2013 at 19:13 blo0p3r 6,8508 gold badges51 silver badges70 bronze badges asked Jan 14, 2013 at 19:05 user1505628user1505628 331 gold badge1 silver badge3 bronze badges 5- 2 There's no guarantee you will be able to tell what country someone es from. Even if you could, they could just disable JS to get around that. – Explosion Pills Commented Jan 14, 2013 at 19:08
- 3 Note that, no matter what, you won't be able to really block people without server access: browsers make it easy to disable Javascript, so anyone who really wants to see your site can totally see it. – Matchu Commented Jan 14, 2013 at 19:08
- 1 How do you intend to determine which country is visiting your website? The IP address of the ining request is widely used, but it will require a third-party service. Browser locale settings are imprecise, since they aren't enforced and it's mon for someone to set their locale to something different from their physical location (e.g., "I live in Mexico, but I am browsing US English.") – Palpatim Commented Jan 14, 2013 at 19:09
- @Matchu is there any script to block countries?I am ok with some experts managing to enter my site using other tricks.Thanks – user1505628 Commented Jan 14, 2013 at 19:11
- I was going to suggest adding a meta-refresh tag, and then disabling it with javascript, but this doesn't work. – Shmiddty Commented Jan 14, 2013 at 19:38
3 Answers
Reset to default 3You can use the visitors IP address and do a geolocation search on it.
See this question to Get Client IP using just Javascript? and then you can pass that to a service like freegeoip to get the information.
From their main page:
http://freegeoip/json/google.?callback=show
Results in:
show({"city": "Mountain View", "region_code": "CA", "region_name": "California", "metrocode": "807", "zipcode": "94043", "longitude": "-122.057", "country_name": "United States", "country_code": "US", "ip": "209.85.145.147", "latitude": "37.4192"});
Of course you can replace google.
with the IP of the visitor.
There are some third party apis that will help you to detect country. You can use the following code to detect country
$.getJSON('http://api.wipmania./jsonp?callback=?', function (data) {
alert('Latitude: ' + data.latitude +
'\n Longitude: ' + data.longitude +
'\n Country: ' + data.address.country);
});
But it is true that people can disable javascript to get in your website. You should block it from server.
Using the thread found Simplest way to detect client locale in PHP to detect country. Then just stop processing the page, redirect or block etc based on country. Or similar based on your server language.