-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvista_ip.php
99 lines (80 loc) · 2.89 KB
/
vista_ip.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
error_reporting(0);
session_start();
// 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);
}
$ip_options = array();
// Consulta para obtener la lista de IPs disponibles
$query = "SELECT DISTINCT ip FROM ubicaciones";
$result = $conn->query($query);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$ip_options[] = $row['ip'];
}
}
if (isset($_POST['selected_ip'])) {
$selected_ip = $_POST['selected_ip'];
// Consulta para obtener las ubicaciones asociadas con la IP seleccionada
$query = "SELECT latitud, longitud, hora FROM ubicaciones WHERE ip = ? ORDER BY timestamp";
$stmt = $conn->prepare($query);
$stmt->bind_param("s", $selected_ip);
$stmt->execute();
$result = $stmt->get_result();
$locations = array();
while ($row = $result->fetch_assoc()) {
$locations[] = $row;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="/img/logo.png">
<title>Historial de Ubicaciones por IP</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<style>
/* Estilos del mapa y contenedor */
#map {
height: 500px;
}
</style>
</head>
<body>
<h1>Historial de Ubicaciones por IP</h1>
<form method="POST" action="">
<label for="selected_ip">Selecciona una IP:</label>
<select name="selected_ip" required>
<?php foreach ($ip_options as $ip) : ?>
<option value="<?php echo $ip; ?>"><?php echo $ip; ?></option>
<?php endforeach; ?>
</select>
<button type="submit">Mostrar Historial</button>
</form>
<?php if (isset($locations)) : ?>
<h2>Historial de Ubicaciones para IP: <?php echo $selected_ip; ?></h2>
<div id="map"></div>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script>
var map = L.map('map').setView([0, 0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
var locations = <?php echo json_encode($locations); ?>;
var polyline = L.polyline([], { color: 'blue' }).addTo(map);
locations.forEach(function (location) {
var lat = parseFloat(location.latitud);
var lon = parseFloat(location.longitud);
var time = location.hora;
L.marker([lat, lon]).addTo(map)
.bindPopup('Hora: ' + time);
polyline.addLatLng([lat, lon]);
});
map.fitBounds(polyline.getBounds());
</script>
<?php endif; ?>
</body>
</html>