Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
How to get visitor's country name for website

I am currently working on my website which have display various places according to visitor's country.

i also tried to this examples but i want to get IP address autometically

here is example code

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>

i am new in PHP so please guide me.. Thanks :)

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Try the following 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>

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda