how to get user location in php code example
Example 1: php get user ip
$ip = $_SERVER['REMOTE_ADDR'];
Example 2: php get location of user
$PublicIP = $_SERVER['REMOTE_ADDR'];
$json = file_get_contents("http://ipinfo.io/$PublicIP/geo");
$json = json_decode($json, true);
$country = $json['country'];
$region = $json['region'];
$city = $json['city'];
Example 3: jquery get location of user
$("#find_btn").click(function () {
if ("geolocation" in navigator){
navigator.geolocation.getCurrentPosition(function(position){
$("#result").html("Found your location <br />Lat : "+position.coords.latitude+" </br>Lang :"+ position.coords.longitude);
});
}else{
console.log("Browser doesn't support geolocation!");
}
});