Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Get visitor city, state, country and other details with address

 Get visitor city, state, country and other details with address by following php code.

<?php
//echo ‘<pre>’; print_r($_SERVER);
$ip = $_SERVER[‘REMOTE_ADDR’]; // the IP address to query
if($ip != ‘::1’ && $_SERVER[‘SERVER_NAME’] != ‘localhost’)
{
$query = @unserialize(file_get_contents(‘http://ip-api.com/php/’.$ip));
if($query && $query[‘status’] == ‘success’) {
echo ‘Hello visitor from ‘.$query[‘city’].’, ‘.$query[‘regionName’].’, ‘.$query[‘country’].’!’;
echo ‘<br />’;
$lat = $query[‘lat’];
$lon = $query[‘lon’];
echo get_location($lat, $lon);
} else {
echo ‘Unable to get location’;
}
echo ‘<br />’;
print_r($query);
}

function get_location($lat, $lon)
{
$url = “http://maps.googleapis.com/maps/api/geocode/json?latlng=”.$lat . “,” . $lon . “&sensor=false”;

$json = @file_get_contents($url);
$data = json_decode($json);

$status = $data->status;
$address = ”;

if ($status == “OK”) {

$address = $data->results[0]->formatted_address;
return $address;
} else
return ”;
}
?>

must watch some other topics :

cake PHP training institute
cake PHP training course
cake php training online

Post a Comment

0 Comments