Compare commits
5 Commits
b7a8602e34
...
22c85234da
Author | SHA1 | Date | |
---|---|---|---|
22c85234da | |||
4bba4f9410 | |||
d928ad2ce3 | |||
63050a8065 | |||
0b08c1ce9c |
14
checkloc.php
Normal file
14
checkloc.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$latitude = $_GET["latitude"];
|
||||
$longitude = $_GET["longitude"];
|
||||
$glink = $_GET["glink"];
|
||||
|
||||
printf("Lat is %s, Long is %s, and glink is %s",$latitude,$longitude,$glink);
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
?>
|
@@ -19,10 +19,11 @@
|
||||
<span role="alert" id="error" aria-hidden="true">Invalid URL</span>
|
||||
|
||||
<br><br>
|
||||
<label for="restricted">Geo-restricted?: </label><input type="checkbox" name="restricted" id="restricted">
|
||||
<label for="restricted">Geo-restricted?: </label> <input type="checkbox" name="restricted" id="restricted"> <span id="loadingText" style="position: relative; left: 20px;"></span>
|
||||
<br><br>
|
||||
<label for="radius">Radius: </label>
|
||||
<select name="radius" id="radius">
|
||||
<label for="radius" hidden="hidden" id="radius_label">Radius: </label> <span id="mandatory-radius" class="mandatory" hidden="hidden">*</span>
|
||||
<select name="radius" id="radius" hidden="hidden">
|
||||
<option value="" selected disabled hidden>Select a radius</option>
|
||||
<option value="5">5 mi</option>
|
||||
<option value="10">10 mi</option>
|
||||
<option value="15">15 mi</option>
|
||||
|
8
index.js
8
index.js
@@ -3,9 +3,9 @@ mycheckbox = document.getElementById("restricted");
|
||||
mycheckbox.addEventListener('change',checkboxCallback);
|
||||
window.onload = function() {
|
||||
if (mycheckbox.checked) {
|
||||
document.getElementById("radiusLabel").hidden = false;
|
||||
document.getElementById("radius_label").hidden = false;
|
||||
document.getElementById("mandatory-radius").hidden = false;
|
||||
var radiusSelect = document.getElementById("radiusSelect");
|
||||
var radiusSelect = document.getElementById("radius");
|
||||
radiusSelect.hidden = false;
|
||||
radiusSelect.required = true;
|
||||
}
|
||||
@@ -30,8 +30,8 @@ function valueRequested() {
|
||||
|
||||
}
|
||||
function checkboxCallback(event) {
|
||||
const radiusLabel = document.getElementById("radiusLabel");
|
||||
const radiusSelect = document.getElementById("radiusSelect");
|
||||
const radiusLabel = document.getElementById("radius_label");
|
||||
const radiusSelect = document.getElementById("radius");
|
||||
const mandatoryRadius = document.getElementById("mandatory-radius");
|
||||
if (event.currentTarget.checked) {
|
||||
radiusLabel.hidden = false;
|
||||
|
@@ -29,7 +29,7 @@
|
||||
exit;
|
||||
} else {
|
||||
if ($row['is_geo'] == true) {
|
||||
header("Location: https://glink.zip/reqloc.html");
|
||||
header("Location: https://glink.zip/reqloc.html?glink=" . $uri);
|
||||
exit;
|
||||
} else {
|
||||
header("Location: " . $row['url']);
|
||||
|
55
reqloc.html
Normal file
55
reqloc.html
Normal file
@@ -0,0 +1,55 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Location needed</title>
|
||||
</head>
|
||||
<body onload="get_location()">
|
||||
This link is geo-restricted. Your location is needed to verify that you are authorized to access this link.
|
||||
|
||||
<script>
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
var glink = params.get("glink");
|
||||
|
||||
var lat;
|
||||
var long;
|
||||
var method = "GET";
|
||||
var request;
|
||||
|
||||
function requestHandler() {
|
||||
if (request.readyState === XMLHttpRequest.DONE) {
|
||||
if (request.status === 200) {
|
||||
alert(request.responseText);
|
||||
} else {
|
||||
console.log("Error sending data to server.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function storeLocation(position) {
|
||||
lat = position.coords.latitude;
|
||||
long = position.coords.longitude;
|
||||
}
|
||||
|
||||
function callbackFunction(position) {
|
||||
storeLocation(position);
|
||||
request = new XMLHttpRequest();
|
||||
request.onreadystatechange = requestHandler;
|
||||
if (method == "GET") {
|
||||
request.open("GET","/checkloc.php?latitude=" + encodeURIComponent(lat) + "&longitude=" + encodeURIComponent(long) + "&glink=" + encodeURIComponent(glink));
|
||||
request.send();
|
||||
} else if (method == "POST") {
|
||||
request.open("POST","/checkloc.php");
|
||||
request.send("latitude=" + encodeURIComponent(lat) + "&longitude=" + encodeURIComponent(long));
|
||||
}
|
||||
}
|
||||
|
||||
function get_location() {
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(callbackFunction);
|
||||
|
||||
} else {
|
||||
alert('You cannot access this GLink as your browser does not support geolocation.');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user