IP

rss

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?

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 1 month 13 days
    #1 by rostislav Oct 27 ’15 at 06:07

    The message was removed by a forum moderator.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 1 month 13 days
    #2 by rostislav Oct 27 ’15 at 06:09

    [#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