Hello, I would like to know if there is a way to get the location of a user who accesses my PHP application, type, return something like this:
Country: Brazil State: bláblá City: Narnia
And if possible you still give the attitude and longitude
Hello, I would like to know if there is a way to get the location of a user who accesses my PHP application, type, return something like this:
Country: Brazil State: bláblá City: Narnia
And if possible you still give the attitude and longitude
You can use the API for this site . Apparently the free version allows up to 1000 requests per day. With PHP, the code can be quite simple:
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
var_dump($details);
The result is something like:
object(stdClass)#1 (7) {
["ip"]=> string(13) "..."
["hostname"]=> string(11) "No Hostname"
["city"]=> string(8) "Curitiba"
["region"]=> string(6) "Parana"
["country"]=> string(2) "BR"
["loc"]=> string(17) "..."
["org"]=> string(30) "AS18881 TELEFÔNICA BRASIL S.A"
}
Some data has been omitted for security reasons.