Skip to content

Instantly share code, notes, and snippets.

@reinvented
Created August 20, 2014 20:23
Show Gist options
  • Save reinvented/6cd15333bb587ba373ae to your computer and use it in GitHub Desktop.
Save reinvented/6cd15333bb587ba373ae to your computer and use it in GitHub Desktop.
A small PHP script that can act as the server-side for the Androind geolocation-tracking app Backtitude.
<?php
$mysqli = new mysqli("localhost", "loc", "[password redacted]", "loc");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if ($_POST) {
$query = sprintf("INSERT into locations (latitude, longitude, loc_timestamp, req_timestamp, accuracy, offset) values ('%s', '%s', '%s', '%s', '%s', '%s')",
mysqli_real_escape_string($mysqli, $_POST['latitude']),
mysqli_real_escape_string($mysqli, $_POST['longitude']),
mysqli_real_escape_string($mysqli, $_POST['loc_timestamp']),
mysqli_real_escape_string($mysqli, $_POST['req_timestamp']),
mysqli_real_escape_string($mysqli, $_POST['accuracy']),
mysqli_real_escape_string($mysqli, $_POST['offset']));
if (mysqli_query($mysqli, $query) === TRUE) {
header("HTTP/1.1 201 OK");
}
else {
printf("INSERT failed: %s\n", $mysqli->connect_error);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment