bwonur
bwonur

Reputation: 11

Determine the location of the session with the IP address

Is there a way to get the estimated location from an end-user's IP address using only php?

I did some research on this. Here "Track the exact location of IP address", they announced that this is not possible.

But I mean, take the location of the service provider.

Even if I could only describe his country, that would be enough for me.

Upvotes: 1

Views: 414

Answers (1)

Amin Alizadeh
Amin Alizadeh

Reputation: 41

You can use server global array to take ip :

ip_user = $_SERVER['REMOTE_ADDR'];

and use this function for get country name :

function ip_details($ip_user) 
{
    $json       = file_get_contents("http://ipinfo.io/{$ip_user}");
    $details    = json_decode($json);
    return $details;
}

Upvotes: 1

Related Questions