gpstools/endpoint.php
2016-08-03 19:37:08 +02:00

32 lines
913 B
PHP

<?php
require_once("config.php");
if (isset($_GET["lat"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lat"]) && isset($_GET["lon"]) && preg_match("/^-?\d+\.\d+$/", $_GET["lon"]) && isset($_GET["device"]) ) {
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO tracker (device, lat, lon) VALUES (" . mysqli_real_escape_string($conn, $_GET['device']) . ", " . mysqli_real_escape_string($conn, $_GET['lat']) . ", " . mysqli_real_escape_string($conn, $_GET['lon']) . ");";
if (!mysqli_query($conn, $sql)) {
die('Error: ' . mysqli_error($conn));
}
mysqli_close($conn);
echo "OK";
} elseif (isset($_GET["tracker"])) {
echo "OK";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'This is an endpoint for compatible GPS trackers only.';
}