-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd.php
58 lines (50 loc) · 1.91 KB
/
d.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
error_reporting(0);
// Configuración de la base de datos MySQL
require('environment_loader.php');
// Crear una conexión a la base de datos MySQL
$conn = new mysqli($servername, $db_username, $db_password, $database);
// Verificar la conexión
if ($conn->connect_error) {
die("Error de conexión a la base de datos: " . $conn->connect_error);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$latitud = isset($_POST['latitud']) ? $_POST['latitud'] : '';
$longitud = isset($_POST['longitud']) ? $_POST['longitud'] : '';
$ip = isset($_POST['ip']) ? $_POST['ip'] : '';
if (!empty($latitud) && !empty($longitud) && !empty($ip)) {
// Obtener la hora actual y el timestamp
$hora = date('H:i:s');
$timestamp = time();
// Verificar si la tabla 'ubicaciones' existe, y si no, crearla
$createTableSQL = "CREATE TABLE IF NOT EXISTS ubicaciones (
id INT AUTO_INCREMENT PRIMARY KEY,
latitud DOUBLE,
longitud DOUBLE,
ip VARCHAR(255),
hora TIME,
timestamp INT
)";
if ($conn->query($createTableSQL) === TRUE) {
// Insertar los datos en la tabla 'ubicaciones'
$insertSQL = "INSERT INTO ubicaciones (latitud, longitud, ip, hora, timestamp) VALUES (?, ?, ?, ?, ?)";
$stmt = $conn->prepare($insertSQL);
$stmt->bind_param("ddssi", $latitud, $longitud, $ip, $hora, $timestamp);
if ($stmt->execute()) {
echo "Datos almacenados en la base de datos MySQL.";
} else {
echo "Error al insertar datos: " . $stmt->error;
}
} else {
echo "Error al crear la tabla 'ubicaciones': " . $conn->error;
}
$stmt->close();
} else {
echo "Datos incompletos";
}
} else {
echo "Acceso denegado";
}
// Cerrar la conexión a la base de datos
$conn->close();
?>