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). // To check if the user is allowed to access the URL, check if the distance between their location and the location in the database is less than the radius. To compute the // distance, use something like Haversine Forumla. ?>