Getting users location

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting users location

Heather and Jon Turgeon

Hi all, I am trying to get the users general location server side (the country). I have tried getContext().getRequest().getRemoteAddr(); bu that just returns 0:0:0:0:0:0:0:1 (was going to use a web service to get the country from the IP address). Has anyone been able to do this and if so can you point me in the right direction? Thanks again.


Jon


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Getting users location

Joaquin Valdez-2
I typically get the setting from the browser locale and language.

Joaquin 

On Jul 9, 2017, at 11:18 AM, Heather and Jon Turgeon <[hidden email]> wrote:

Hi all, I am trying to get the users general location server side (the country). I have tried getContext().getRequest().getRemoteAddr(); bu that just returns 0:0:0:0:0:0:0:1 (was going to use a web service to get the country from the IP address). Has anyone been able to do this and if so can you point me in the right direction? Thanks again.


Jon

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Getting users location

Luis Tiago Rico
You can also use HTML 5 location services from specs! 

Em 09/07/2017 6:34 da tarde, "Joaquin Valdez" <[hidden email]> escreveu:
I typically get the setting from the browser locale and language.

Joaquin 

On Jul 9, 2017, at 11:18 AM, Heather and Jon Turgeon <[hidden email]> wrote:

Hi all, I am trying to get the users general location server side (the country). I have tried getContext().getRequest().getRemoteAddr(); bu that just returns 0:0:0:0:0:0:0:1 (was going to use a web service to get the country from the IP address). Has anyone been able to do this and if so can you point me in the right direction? Thanks again.


Jon

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Getting users location

Stan Broné
In reply to this post by Heather and Jon Turgeon
Straight from the top of my head (and from a bus!)... But isn't this  
just happening because you are accessing the website via  
http://localhost:8080?

Did you try this from a production server on the internet? I would  
expect that to work. Just like I would expect it to return your LAN ip  
if you access the website through that (e.g. http://192.168.0.1:8080)

Or maybe I am just way off. It's 11PM trying to get home...

Citeren Heather and Jon Turgeon <[hidden email]>:

> Hi all, I am trying to get the users general location server side  
> (the country). I have tried  
> getContext().getRequest().getRemoteAddr(); bu that just returns  
> 0:0:0:0:0:0:0:1 (was going to use a web service to get the country  
> from the IP address). Has anyone been able to do this and if so can  
> you point me in the right direction? Thanks again.
>
>
> Jon
>



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Getting users location

Rick Grashel
In reply to this post by Heather and Jon Turgeon
That IPv6 address is localhost.  So you maybe have been trying to access the site from the server itself.  I don't know of any situation (outside of IP spoofing) where localhost would be returned from that call.  Did you actually try to hit your web service/page from someplace on the public internet?

Regardless, getRemoteAddr() is not fully dependable anyways.  If it were me, I would first check for the presence of an "X-Forwarded-For" header and use that.  If that is null (or if it is not a valid IP address -- or a listing of IP addresses/ranges), then fall back to getRemoteAddr().  You could even check one against the other.

If you are fronting your own application server with a load balancer or firewall, then you will undoubtedly need to use the "X-Forwarded-For" header.  Otherwise, the getRemoteAddr() will return the IP address of your own firewall.

-- Rick


On Sun, Jul 9, 2017 at 12:18 PM, Heather and Jon Turgeon <[hidden email]> wrote:

Hi all, I am trying to get the users general location server side (the country). I have tried getContext().getRequest().getRemoteAddr(); bu that just returns 0:0:0:0:0:0:0:1 (was going to use a web service to get the country from the IP address). Has anyone been able to do this and if so can you point me in the right direction? Thanks again.


Jon


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users