简体   繁体   中英

find ip address in codeigniter

I tried to add geolocation on my site so i will get customer current location for that i want ip address which i did not get.

<?php include('doctype.php');?>
<header>
  <?php include('topHeader.php');?>
  <?php include('searchArea.php');?>

</header>
<?php include('nav.php');?>
<div class="container">
  <section>
<?php  
$b=get_client_ip();
echo $b;
function get_client_ip() {
    $ipaddress = '';
     if($_SERVER['REMOTE_ADDR'])
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}?>
  </section>
</div>
<?php include('footer.php');?>

this is my code i tried to get ip address for geolocation. did you know any geolaction example to get customer current city.

Best way of get current location using geolocation

Use below get the client current location Latitude & Longitude

<!DOCTYPE html>
<html>
<body onload="getlocation()">

<script>

function getlocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else { 
        alert("Geolocation is not supported by this browser.");
    }
}

function showPosition(position) {
   alert("Latitude: " + position.coords.latitude + 
    "\n Longitude: " + position.coords.longitude);  
}
</script>

</body>
</html>

This latitude and longitude based display google map marker

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM