You can use this:
$ip
is user's ip address.
$ip = $_SERVER['REMOTE_ADDR'];
$data = file_get_contents("http://www.geoplugin.net/json.gp?ip=". $ip);
$data = json_decode($data);
echo $data->geoplugin_countryName; // and so on
This question already has an answer here:
I found many results, but i didn't get any solution for Ip's. I want to find the user ip details all over the world by using php, but not able to find it.
</div>