Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access - To know from which country the user is accessing my application

In my web application , I need to give access only to the users who are accessing my application from India. I need to block the users from accessing my application when they try to access outside India.(i.e., I willnot allow them to login and will show an error pop-up) Can anyone please tell if this is possible?

like image 757
user1514499 Avatar asked Aug 08 '12 07:08

user1514499


1 Answers

Add a Filter which checks for requests and

String ip = request.getRemoteAddress();

Use hostip service api to check for location

For example

http://api.hostip.info/country.php?ip=74.125.236.206

This will give you country code IN

If you don't get IN then from Filter

response.sendRedirect("someUrl");
return;

otherwise allow request

chain.doFilter(request, wrapper);

See

  • hostip FAQ
like image 117
jmj Avatar answered Sep 20 '22 02:09

jmj