Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.