2017-04-18 3 views
1

erhält Ich arbeite zurzeit an meiner Web site, die verschiedene Plätze entsprechend dem Land des Besuchers anzeigen lassen.Wie man den Namen des Landes des Besuchers für Website

Ich habe versucht, auch diese Beispiele, aber ich will

hier ist

HTML

<input type="text" id="ip" /> 
<input type="button" value="Get country of IP" id="submit" /> 

JavaScript Beispielcode

<script type="text/javascript"> 
$(function() { 
    $("#submit").click(function() { 
    if ($('#ip').val()) { 
     var ip = $('#ip').val(); 

     // the request will be to http://www.geoplugin.net/json.gp?ip=my.ip.number but we need to avoid the cors issue, and we use cors-anywhere api. 

     $.getJSON("https://cors-anywhere.herokuapp.com/http://www.geoplugin.net/json.gp?ip=" + ip, function(response) { 
     console.log(response); 
     // output an object which contains the information. 
     $("#content").html("Hello visitor from " + response.geoplugin_countryName); 

     }); 
    } else { 
     alert("Please provide a IP"); 
    } 
    }); 
}); 

</script> 
autometically IP-Adresse erhalten

i in PHP bin hier so bitte leite mich .. Danke :)

+1

, warum Sie, indem Sie die geoplugin docs nicht starten? – Akintunde007

+0

Sie können Besucher IP-Adresse mit Land mit GEO IP erhalten https://github.com/maxmind/geoip-api-php – vinox

Antwort

3

Versuchen Sie, den folgenden Code

// Jquery 
 
$.getJSON("http://freegeoip.net/json/", function(data) { 
 
    var ip = data.ip; 
 
    var country = data.country_name; 
 
    $("#ip").val(ip); 
 
    $("#content").html("Hello visitor from " + country); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="text" id="ip" /> 
 
<input type="button" value="Get country of IP" id="submit" /> 
 
<div id="content"> 
 
</div>

+0

Danke Kumpel .. :) –

Verwandte Themen