Skip to content

Instantly share code, notes, and snippets.

@FerFuego
Created January 8, 2022 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FerFuego/e11b23ba7e7e7ced5b9124b0ca7cca5c to your computer and use it in GitHub Desktop.
Save FerFuego/e11b23ba7e7e7ced5b9124b0ca7cca5c to your computer and use it in GitHub Desktop.
This snippet is for get complete location users by your ip address
<?php
/**
* Get My Location object
* Request to API endpoint https://geolocation-db.com
* @param REMOTE_ADDR
*/
function get_user_location_by_ip () {
$response = file_get_contents('https://geolocation-db.com/json/'.$_SERVER['REMOTE_ADDR']);
$location = json_decode($response, true);
return $location;
}
?>
// https://geolocation-db.com/json/200.122.93.178
{
"country_code": "AR",
"country_name": "Argentina",
"city": "Bell Ville",
"postal": "2550",
"latitude": -32.6167,
"longitude": -62.7,
"IPv4": "200.122.93.178",
"state": "Cordoba"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment