• Post Reply Bookmark Topic Watch Topic
  • New Topic

help to determine a request coming from which country

 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i have to hide/unhide certain portion on my website based upon the audience. for example if the request comes from India i have to hide certain content and if the request comes from US then i have to show some extra content.
is there a way i can determine if the request comes from US or India.
i have used request.getLocale() and tried from both location from my home computer in india and us and it always return en_US.
is there a way to differentiate
Please let me know

Thanks
Rashid
 
Aurelian Tutuianu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getLocale() gives you the localization used on a computer. Default is usually en_US. So, is meaningless. Even if the default values would be set up by country, tat would not mean that you cannot change.
The only way I think right now is to find the provider of the IP used by country and in that way to find the country. Doing so can cost time. I really don't know how is done. Firefiox has a plugin which shows the flag of the country from which is the site. Maybe you can see their code to understand their technique (is open source by the way).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65528
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aurelian Tutuianu wrote:request.getLocale() gives you the localization used on a computer.

That is not really correct.

request.getLocale() will report the locale sent on the request as the Accept-Language header, which may or may not reflect the locale of the system. If no header is provided, the locale will be that of the server, not the browser.

A quick review of the javadoc would have told you this.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The GeoIP Java API can tell you that based on the request's IP address.
 
Aurelian Tutuianu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:That is not really correct.
A quick review of the javadoc would have told you this.
I apologize for that, of course you are right. I did not seen request. I answered fast because of the fact that this method getLocale is unnaropriate to identify a physic location, only a relative configuration of a system. That's all.
 
Darvesh Niz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that means getLocale does not solve my problem.
apart from geoApi, Is there any third party open source api which provides this service.
Also can somebody suggest whats the correct way to determine automatically from where the request is coming.

Thanks
Rashid
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GeoIP is a 3rd party open source API; what else are you looking for?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!