1
現在、私は訪問者の国に応じて様々な場所を表示している私のウェブサイトで働いています。ウェブサイトの訪問者の国名を取得する方法
私はまた、この例に試みたが、私はautometically
ここでIPアドレスを取得したいのコード例
HTML
<input type="text" id="ip" />
<input type="button" value="Get country of IP" id="submit" />
はJavaScript
<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>
です
私は私を導いてくださいPHPに新しいです..
を試してみてくださいなぜあなたはgeopluginのドキュメントを確認することから始めませんか? – Akintunde007
GEO IP https://github.com/maxmind/geoip-api-php – vinox