IP
Posted by Sebastian Haugland - Oct 26 ’15 at 03:14
Hi
I would like to see the IP of the client (to determine the location of the user), any ideas?
-
rostislavModeratorMember for: 5 years 8 months 20 days
The message was removed by a forum moderator.
-
rostislavModeratorMember for: 5 years 8 months 20 days
[#1]:
Here are a couple of options:
1. Use a REST service, e.g.
$.ajax({ url: "http://freegeoip.net/json/" }).then(function(data) { console.log(data.ip); //data contains other things, like country, latitude, longitute, etc });
2. Append a 3rd party script to your page: Add this code on form load:
$('head').append('<script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script>')
This will append a script to your page. Then you will be able to access the IP via myip variable, e.g.:
alert(myip);
This (probably) wouldn't work if your site uses the https protocol. Also, from stackoverflow: "...this can be easily spoofed (through either use of proxies or spoofed request headers...".
Displaying 1 to 2 of 2 messages