Friday, January 13

Get City Country By IP Address in PHP

index.php

<?php
$ip_addressget=$_SERVER['REMOTE_ADDR'];

/*Get user ip address details with geoplugin.net*/
$geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_addressget;

$addrDetailsArr = unserialize(file_get_contents($geopluginURL));

/*Get City name by return array*/
$city = $addrDetailsArr['geoplugin_city'];

/*Get Country name by return array*/
$country = $addrDetailsArr['geoplugin_countryName'];

/*Comment out these line to see all the posible details*/
/*echo '<pre>';
print_r($addrDetailsArr);
die();*/

if(!$city){
   $city='Not Define';
}if(!$country){
   $country='Not Define';
}
echo '<strong>IP Address is</strong>:- '.$ip_address.'<br/>';
echo '<strong>City is </strong>:- '.$city.'<br/>';
echo '<strong>Country is </strong>:- '.$country.'<br/>';
?>

No comments:

Post a Comment

10 Best Chatting Apps In India

  The modern world is all about Internet. There was a time when people use to pay high telephone bills to stay in touch with their friends a...