IP
- Sebastian Haugland
- Posts: 43
- Joined: Fri Sep 19, 2014
- Contact:
Hi
I would like to see the IP of the client (to determine the location of the user), any ideas?
I would like to see the IP of the client (to determine the location of the user), any ideas?
Here are a couple of options:
1. Use a REST service, e.g.
2. Append a 3rd party script to your page: Add this code on form load:
This will append a script to your page. Then you will be able to access the IP via myip variable, e.g.:
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...".
1. Use a REST service, e.g.
Code: Select all
$.ajax({
url: "http://freegeoip.net/json/"
}).then(function(data) {
console.log(data.ip); //data contains other things, like country, latitude, longitute, etc
});
Code: Select all
$('head').append('<script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script>')
Code: Select all
alert(myip);
-
- Information
-
Who is online
Users browsing this forum: No registered users and 7 guests