184 lines
6.1 KiB
PHP
Executable file
184 lines
6.1 KiB
PHP
Executable file
<?php
|
||
// Use a function to get stats safely
|
||
function getVisitStats() {
|
||
$visitsFile = "visits.json";
|
||
|
||
if (!file_exists($visitsFile)) {
|
||
return [
|
||
"total_visits" => 0,
|
||
"unique_visits" => 0,
|
||
"last_visit" => time(),
|
||
"monthly" => [],
|
||
"weekly" => [],
|
||
"browsers" => [],
|
||
"operating_systems" => [],
|
||
];
|
||
}
|
||
|
||
// Read the stats from the file
|
||
$fp = fopen($visitsFile, "r");
|
||
if ($fp === false) {
|
||
die("Error opening the file.");
|
||
}
|
||
|
||
$data = fgets($fp);
|
||
fclose($fp);
|
||
|
||
$stats = json_decode($data, true);
|
||
|
||
// Check if JSON decode failed
|
||
if ($stats === null) {
|
||
error_log("Failed to decode visits.json: " . json_last_error_msg());
|
||
return [
|
||
"total_visits" => 0,
|
||
"unique_visits" => 0,
|
||
"last_visit" => time(),
|
||
"monthly" => [],
|
||
"weekly" => [],
|
||
"browsers" => [],
|
||
"operating_systems" => [],
|
||
];
|
||
}
|
||
|
||
return $stats;
|
||
}
|
||
|
||
$stats = getVisitStats();
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Website Stats</title>
|
||
<link rel="stylesheet" href="assets/styles.css"> <!-- Linking your provided CSS -->
|
||
<style>
|
||
/* Specific labels for each table in responsive mode */
|
||
@media (max-width: 768px) {
|
||
#monthlyTable td:nth-of-type(1):before { content: "Month"; }
|
||
#monthlyTable td:nth-of-type(2):before { content: "Visits"; }
|
||
|
||
#weeklyTable td:nth-of-type(1):before { content: "Week"; }
|
||
#weeklyTable td:nth-of-type(2):before { content: "Visits"; }
|
||
|
||
#browserTable td:nth-of-type(1):before { content: "Browser"; }
|
||
#browserTable td:nth-of-type(2):before { content: "Visits"; }
|
||
|
||
#osTable td:nth-of-type(1):before { content: "OS"; }
|
||
#osTable td:nth-of-type(2):before { content: "Visits"; }
|
||
}
|
||
</style>
|
||
<script src="assets/table-sort.js"></script>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<h1>Website Stats</h1>
|
||
|
||
<section class="section">
|
||
<h2>General Stats</h2>
|
||
<p><strong>Total Visits:</strong> <?php echo $stats[
|
||
"total_visits"
|
||
]; ?></p>
|
||
<p><strong>Unique Visits:</strong> <?php echo $stats[
|
||
"unique_visits"
|
||
]; ?></p>
|
||
<p><strong>Last Visit Timestamp:</strong> <?php echo date(
|
||
"Y-m-d H:i:s",
|
||
$stats["last_visit"]
|
||
); ?></p>
|
||
</section>
|
||
|
||
<!-- Monthly Visits Table -->
|
||
<section class="section">
|
||
<h2>Monthly Visits</h2>
|
||
<table id="monthlyTable" class="jobsTable">
|
||
<thead>
|
||
<tr>
|
||
<th>Month</th>
|
||
<th>Visits</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($stats["monthly"] as $month => $count): ?>
|
||
<tr>
|
||
<td><?php echo $month; ?></td>
|
||
<td><?php echo $count; ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<!-- Weekly Visits Table -->
|
||
<section class="section">
|
||
<h2>Weekly Visits</h2>
|
||
<table id="weeklyTable" class="jobsTable">
|
||
<thead>
|
||
<tr>
|
||
<th>Week</th>
|
||
<th>Visits</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($stats["weekly"] as $week => $count): ?>
|
||
<tr>
|
||
<td>Week <?php echo $week; ?></td>
|
||
<td><?php echo $count; ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<!-- Browser Stats Table -->
|
||
<section class="section">
|
||
<h2>Browser Stats</h2>
|
||
<table id="browserTable" class="jobsTable">
|
||
<thead>
|
||
<tr>
|
||
<th>Browser</th>
|
||
<th>Visits</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($stats["browsers"] as $browser => $count): ?>
|
||
<tr>
|
||
<td><?php echo $browser; ?></td>
|
||
<td><?php echo $count; ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<!-- Operating System Stats Table -->
|
||
<section class="section">
|
||
<h2>Operating System Stats</h2>
|
||
<table id="osTable" class="jobsTable">
|
||
<thead>
|
||
<tr>
|
||
<th>Operating System</th>
|
||
<th>Visits</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach (
|
||
$stats["operating_systems"]
|
||
as $os => $count
|
||
): ?>
|
||
<tr>
|
||
<td><?php echo $os; ?></td>
|
||
<td><?php echo $count; ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
</div>
|
||
<section class="section">
|
||
<h2>Just a Quick Note</h2>
|
||
<p><em>We know, we know… this isn’t the most sophisticated way to track visitors. No fancy servers or big data here, just some humble tracking behind the scenes. But hey, it’s privacy-friendly! We’re not tracking your every move or creating a digital dossier, just counting visits in a way that doesn’t require selling your personal info to the highest bidder. So enjoy the stats, and know that your privacy is safe with us!</em></p>
|
||
</section>
|
||
|
||
</body>
|
||
</html>
|