There are open/free APIs that allow geolocation based on the IP address. IP address of a mobile should be geo-correct.
I use this site, with a CURL function to return the Geo information. Go to the URL in the code to get details on the return values.
function grabIpInfo($ip) {
//$ip = '185.164.57.189'; // france
//$ip = '110.33.122.75'; // australia
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.ipgeolocationapi.com/geolocate/" . $ip);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$returnData = curl_exec($curl);
curl_close($curl);
return $returnData;
}
You’ll need to pass the IP address, which is available with
$_SERVER["REMOTE_ADDR"]
That might get you started on the code you need. And testing (I hard coded some other-country IP addresses for my testing, as shown in the code).