Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

teampoison's avatar

Intl-tel-input Country Code Not Fatch From IP Address

i use intl-tel in html form and add a code for auto select country from user ip address. it was only work when user device location are on. But i allow country select from ip address. How i do this if user location are off. because if location are off then we find the location from ip address. i want code fetch country code from user ip address not device location.

<script>
 var input = document.querySelector("#phone_number");
 window.intlTelInput(input, {
   separateDialCode: true,
   initialCountry: "auto",
   hiddenInput: "phone",
   geoIpLookup: function (success) {
     fetch("https://api.ipdata.co/?api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
        .then(function(response) {
          if (!response.ok) return success("");
          return response.json();
        })
        .then(function(ipdata) {
          success(ipdata.country_code);
        });
   },
   utilsScript: "https://intl-tel-input.com/node_modules/intl-tel-input/build/js/utils.js?1638200991544" // just for formatting/placeholders etc
 }); 
 </script>
0 likes
0 replies

Please or to participate in this conversation.