OwnTracks receiver script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = file_get_contents('php://input'); | |
$json = json_decode($data); | |
header("Content-type: application/json"); | |
if ($json->_type !== 'location') { | |
return; | |
} | |
$db = new mysqli('localhost:3306', 'otr', 'sshhh', 'otr'); | |
if ($db->connect_error) { | |
die('Connection failed: ' . $db->connect_error); | |
} | |
$stmt = $db->prepare('INSERT INTO recordings (user, device, acc, alt, batt, bs, conn, created_at, lat, lon, t, tid, tst, vac, vel) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);'); | |
if ($stmt === false) { | |
die('failed to prepare query: ' . $db->error); | |
} | |
if ($stmt->bind_param('ssiiiisiddssiii', $user, $device, $json->acc, $json->alt, $json->batt, $json->bs, $json->conn, $json->created_at, $json->lat, $json->lon, $json->t, $json->tid, $json->tst, $json->vac, $json->vel) === false) { | |
die('failed to bind params: ' . $stmt->error); | |
} | |
$user = $_SERVER['HTTP_X_LIMIT_U']; | |
$device = $_SERVER['HTTP_X_LIMIT_D']; | |
if ($stmt->execute() === false) { | |
die('failed to insert: ' . $stmt->error); | |
} | |
$stmt->close(); | |
$db->close(); | |
print json_encode(array()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment