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).