2

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?

blo0p3r
  • 6,790
  • 8
  • 49
  • 68
user1505628
  • 23
  • 1
  • 3
  • 2
    There's no guarantee you will be able to tell what country someone comes from. Even if you could, they could just disable JS to get around that. – Explosion Pills Jan 14 '13 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 Jan 14 '13 at 19:08
  • 1
    How do you intend to determine which country is visiting your website? The IP address of the incoming 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 common 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 Jan 14 '13 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 Jan 14 '13 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 Jan 14 '13 at 19:38

3 Answers3

3

You 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.net/json/google.com?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.com with the IP of the visitor.

Community
  • 1
  • 1
sachleen
  • 30,730
  • 8
  • 78
  • 73
0

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.com/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.

Avigit
  • 284
  • 2
  • 3
  • 13
-2

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.

Community
  • 1
  • 1
Leeish
  • 5,203
  • 2
  • 17
  • 45
  • 2
    The question is asking without using server side technologies. – blo0p3r Jan 14 '13 at 19:12
  • Unfortunately,i dont have control over any server settings.But thank you for your efforts. – user1505628 Jan 14 '13 at 19:13
  • Look down in the post. It does it via an api. Do it via javascript and then redirect via window.location. Here, ajax this and use the result: http://api.hostip.info/get_html.php?ip=12.215.42.19 – Leeish Jan 14 '13 at 19:15
  • @Leeish Can I suggest that you place your link to the specific answer you are refering and not the question in general. – blo0p3r Jan 14 '13 at 19:17
  • Pardon my ignorance, but I understand how the links are used via the URL but how do I obtain/generate the link to the appropriate location in the thread? – Leeish Jan 14 '13 at 20:12
  • @Leeish Below an answer there are 3 links `share|edit|flag` If you `share` that answer you get a permalink to that specific answer. – blo0p3r Jan 14 '13 at 20:55
  • Thanks. Never touched the button, figured it would bring up a social share dialog. – Leeish Jan 14 '13 at 21:30