get city name from ip address using php

get city name from ip address using php

Get city name from ip address using php ;-


Finding Geo location and user detail by IP for security Purpose or For booking site now You can find all detail using PHP and And ipapi.co 

 


<?php
$url = "https://ipapi.co/122.160.84.88/json/";
 $ch = curl_init();  
 
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
    $output=curl_exec($ch);
 
    if($output === false)
    {
        echo "Error Number:".curl_errno($ch)."<br>";
        echo "Error String:".curl_error($ch);
    }
    curl_close($ch);
    $data = json_decode($output,true);

?>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>get city name from ip address using php</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<style>
td>b{color:blue;}
</style>
<div class="container">
  <h2>Detail Via IP</h2>         
  <table class="table table-bordered">

    <tbody>
    
      <tr>
        <td><strong>Region</strong></td>
        <td><b><?php  echo $data['region']; ?></b></td>
      </tr>
      
      <tr>

        <td><strong>City</strong></td>
        <td><b><?php  echo $data['city']; ?></b></td>
      </tr>
      
      
      <tr>
        
        <td><strong>Service Provider</strong></td>
        <td><b><?php  echo $data['org']; ?></b></td>
    
      </tr>
      
      
      <tr>
        <td><strong>Postal Code</strong></td>
        <td><b><?php  echo $data['postal']; ?></b></td>
      </tr>
      
      
      <tr>
        <td><strong>Latitude</strong></td>
        <td><b><?php  echo $data['latitude']; ?></b></td>
      </tr>
      
      
      <tr>
        <td><strong>Longitude</strong></td>
        <td><b><?php  echo $data['longitude']; ?></b></td>
      </tr>
      
    </tbody>
  </table>
</div>

</body>
</html>

Demo

Download Hare

Total Coments (1)

  1. ARNAB MUNSHI
    • 20 Nov 2017

    awesome ...