How to get location information from ip address in php

PHP
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
echo $details->city; // -> "Mountain View"$clientIPAddress=$_SERVER['REMOTE_ADDR']; 
Source

Also in PHP: