How to block users based on their location?

Asked

Viewed 95 times

0

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

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

How to implement such functionality?

Let’s consider that all users who will access the system will not be making use of proxy.

I’m using php.

1 answer

0

On the php website they refer to the extension GEOIP.

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

See in the documentation here.

Or you can use this api here https://ipinfo.io/.

Can consult before displaying the posts available to the user of the city in question, and decide whether or not to display

Ex

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

I think that would suit the situation you need.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.