function distanceCenter($storeBean) { $lat = $storeBean->getLat(); $lng = $storeBean->getLng(); $point = new Point($lat, $lng); return distanceBetweenPoints($point, $this->getCenter(), $this . getUnit()); }
//Generate the query with prepared statements (stops sql injection) $statement = $conn->prepare("SELECT hash FROM login WHERE username=:login"); $statement->execute(array("login" => $login)); //Get the data (should only be 1 hash, else its an error) $row = $statement->fetch(); //No Value returned (username doesnt exist) if ($row === false) { echo "<h1>Error, username or password incorrect</h1>"; } elseif (password_verify($passwordUser, $row[0])) { $phoneLocation = getPhoneLocation($login); if ($phoneLocation === "") { header("Location: http://mo-auth.xyz/login.php?error=timeout"); exit; } //Change to use distance calculator if (distanceBetweenPoints($lat, $long, $phoneLocation['lat'], $phoneLocation['lng']) < 5) { //less than 5 km, ok session_start(); $_SESSION['login_status'] = true; $_SESSION['username'] = $login; header("Location: http://mo-auth.xyz/account.php"); } else { //Need to error header("Location: http://mo-auth.xyz/login.php?error=locationinvalid"); exit; } } else { echo "<h1>Error, username or password incorrect</h1>"; } } catch (PDOException $e) { echo "Error: " . $e->getMessage();
$newbusiness['geometry']['location']['lng'] = $row['longitude']; $newbusiness['place_id'] = $row['id']; $newbusiness['name'] = $row['name']; $newbusiness['image_url'] = $row['imageurl']; $newbusiness['vicinity'] = $row['address']; $search['results'][] = $newbusiness; } // Return all rows in removelocations $queryremovelocations = <<<SQL SELECT * FROM `removelocations` SQL; $queryremovelocationsresult = $db->query($queryremovelocations); // Remove all businesses that have a matching ID in removelocations while ($row = $queryremovelocationsresult->fetch_assoc()) { for ($i = 0; $i < count($search['results']); ++$i) { if ($search['results'][$i]['place_id'] == $row['locationid']) { unset($search['results'][$i]); } } } // Calculate distance of user to each business for ($i = 0; $i < count($search['results']); $i++) { $search['results'][$i]['distance'] = distanceBetweenPoints($arguments['latitude'], $arguments['longitude'], $search['results'][$i]['geometry']['location']['lat'], $search['results'][$i]['geometry']['location']['lng']); } // Now sort by distance function resultsSortCompare($a, $b) { return strcmp($a['distance'], $b['distance']); } usort($search['results'], 'resultsSortCompare'); echo json_encode($search);