Hi I am setting up a WordPress website for a venue. I need to lock the latitude and longitude of the venue so that the website only open inside the venue, i tried setting it up on local host to only open with the Wifi but most of the customers use their 4G. any help would be appriciated! Thanks
Hi I am setting up a WordPress website for a venue. I need to lock the latitude and longitude of the venue so that the website only open inside the venue, i tried setting it up on local host to only open with the Wifi but most of the customers use their 4G. any help would be appriciated! Thanks
Share Improve this question asked Jun 27, 2020 at 7:53 Aetzad AsgharAetzad Asghar 155 bronze badges 2- I don't think you can. You can write script that asks the client for permission to use their location and submit that back to the website for validation for users that aren't on your wifi, and then set a short-lived cookie (a few hours?) to remember that, but you're relying on the location they send back so you can't guarantee someone isn't trying to trick you. – Rup Commented Jun 27, 2020 at 9:27
- The only way you could get a trustworthy GPS location for 4G devices is if there was a way to query that from the mobile networks. But there almost certainly isn't. You could ask everyone to connect to wifi briefly, and use that to set a cookie that your site can check once they switch back to 4G, but that's making your wifi a single point of failure and in my experience venue wifi isn't reliable. – Rup Commented Jun 27, 2020 at 9:29
1 Answer
Reset to default 0There 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/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).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742297140a4417353.html
评论列表(0条)