PHP Besucherprotokoll: 24 Stunden Besucherdaten anzeigen und Einbetten
<!DOCTYPE html>
<html>
<head>
<title>Besucherprotokoll</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
border-bottom: 1px solid #ddd;
}
tr:hover {
background-color: #f5f5f5;
}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<?php
// Verbindung zur MySQL-Datenbank herstellen
$servername = 'localhost';
$username = 'root';
$password = '123456';
$dbname = 'visitors';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die('Verbindung fehlgeschlagen: ' . $conn->connect_error);
}
// Besucherinformationen in die Datenbank einfgen
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO visitors (ip, date) VALUES ('$ip', '$date')";
$conn->query($sql);
// Besucherprotokoll anzeigen
$sql = "SELECT * FROM visitors WHERE date >= DATE_SUB(NOW(), INTERVAL 24 HOUR)";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>
";
echo "<tr><th>ID</th><th>IP</th><th>Datum</th></tr>
";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"] . "</td><td>" . $row["ip"] . "</td><td>" . $row["date"] . "</td></tr>
";
}
echo "</table>
";
} else {
echo "Keine Besucher in den letzten 24 Stunden.";
}
$conn->close();
?>
<?php
// Code, um diese Seite von einer anderen Seite aufzurufen
echo '<a href="visitor_log.php">Besucherprotokoll anzeigen</a>';
?>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/l6LU 著作权归作者所有。请勿转载和采集!