From 96abdd985227307d4db5fbd666504db86d27556b Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 19 Jun 2023 01:13:31 -0500 Subject: [PATCH] Added code to check if the user is within the radius for the GLink --- checkloc.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/checkloc.php b/checkloc.php index 440259f..9ab84c1 100644 --- a/checkloc.php +++ b/checkloc.php @@ -1,9 +1,63 @@ withPersistentSessions(true)->build(); + $keyspace = 'glink'; + $session = $cluster->connect($keyspace); + $statement = $session->prepare('SELECT latitude,longitude,radius,url FROM data WHERE shortlink=? ALLOW FILTERING;'); + $result = $session->execute($statement,array('arguments' => array($glink))); + + $link_lat = floatval($result[0]['latitude']); + $link_lat = $link_lat * (M_PI / 180); + $link_long = floatval($result[0]['longitude']); + $link_long = $link_long * (M_PI / 180); + $target_radius = intval($result[0]['radius']); + + $url = $result[0]['url']; + + $distance = haversine_distance($link_lat, $link_long, $user_lat, $user_long, 6371.009); + $distance = km_to_miles($distance); + + if ($distance <= $target_radius) { + printf("%s",$url); + } else { + printf("B"); + } // Check the database to see if user is allowed to access the URL. If they are, respond 'Yes' (for the time being), if they are not, respond 'No' (for the time being).