How do I block users based on their location?

0

I have an application where users type A posts information. By default these posts will be available to any web user, anywhere in the world.

But there is a possibility for user A to restrict his post 123 to some cities. In other words, userA has banned his post 123 from being available to people who access from the cities of Brasilia, Salvador and André da Rocha (small city of Rio Grande do Sul). I'm using random examples from small to medium-sized cities.

How to implement such functionality?

Let's consider that all users who will access the system will not be using proxy.

I'm using php.

    
asked by anonymous 05.04.2018 / 15:55

1 answer

0

On the php site they reference the GEOIP extension.

With it you can get detailed information about a host name or an Ip.

See the documentation here .

Or you can use this api link .

You can check before displaying the posts available to the user of the city in question, and make the decision to display or not

Ex

$.get("https://ipinfo.io", function(response) {
  console.log(response.ip, response.country);
}, "jsonp")

I think this would suit the situation you need.

  

In the community so stack (English) has already been asked this question and has   good solution implemented there, check here .

    
05.04.2018 / 16:04