Created
January 8, 2022 23:19
-
-
Save FerFuego/e11b23ba7e7e7ced5b9124b0ca7cca5c to your computer and use it in GitHub Desktop.
This snippet is for get complete location users by your ip address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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