Besucherzähler für SPA-Landing hinzugefügt
- api/counter.php: PHP-basierter Zähler mit Session-Tracking - Zähler-Anzeige im Footer der Landingpage - counter.txt in .gitignore aufgenommen 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,6 +13,9 @@ node_modules/
|
|||||||
# Temp files
|
# Temp files
|
||||||
*.tmp
|
*.tmp
|
||||||
*.bak
|
*.bak
|
||||||
|
|
||||||
|
# Counter data
|
||||||
|
api/counter.txt
|
||||||
kostenschaetzung/
|
kostenschaetzung/
|
||||||
schadendokumentation/
|
schadendokumentation/
|
||||||
zeitwert/
|
zeitwert/
|
||||||
|
|||||||
33
api/counter.php
Normal file
33
api/counter.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Besucherzähler API für SPA-Landing
|
||||||
|
* Gibt den aktuellen Zählerstand als JSON zurück und zählt bei neuen Sessions
|
||||||
|
*/
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
|
||||||
|
$counterFile = __DIR__ . '/counter.txt';
|
||||||
|
|
||||||
|
// Zähler lesen oder initialisieren
|
||||||
|
if (file_exists($counterFile)) {
|
||||||
|
$count = (int) file_get_contents($counterFile);
|
||||||
|
} else {
|
||||||
|
$count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Session starten für Duplikat-Erkennung
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// Nur zählen wenn noch nicht in dieser Session gezählt
|
||||||
|
if (!isset($_SESSION['spa_counted'])) {
|
||||||
|
$count++;
|
||||||
|
file_put_contents($counterFile, $count);
|
||||||
|
$_SESSION['spa_counted'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON-Antwort
|
||||||
|
echo json_encode([
|
||||||
|
'count' => $count,
|
||||||
|
'formatted' => number_format($count, 0, ',', '.')
|
||||||
|
]);
|
||||||
15
index.html
15
index.html
@@ -280,12 +280,13 @@
|
|||||||
</main>
|
</main>
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<p>artetui.de · SPA Platform · Alle Daten werden lokal gespeichert</p>
|
<p>artetui.de · SPA Platform · Alle Daten werden lokal gespeichert</p>
|
||||||
|
<p style="margin-top:0.5rem;font-size:0.85rem;opacity:0.7;">Besucher: <span id="visitor-count">...</span></p>
|
||||||
<p style="text-align:center;margin-top:0.5rem;font-size:0.85rem;">
|
<p style="text-align:center;margin-top:0.5rem;font-size:0.85rem;">
|
||||||
<a href="#" onclick="openImpressum();return false;" style="color:#6b7280;text-decoration:none;">Impressum</a>
|
<a href="#" onclick="openImpressum();return false;" style="color:#6b7280;text-decoration:none;">Impressum</a>
|
||||||
<span style="color:#d1d5db;margin:0 0.5rem;">|</span>
|
<span style="color:#d1d5db;margin:0 0.5rem;">|</span>
|
||||||
<a href="#" onclick="openDatenschutz();return false;" style="color:#6b7280;text-decoration:none;">Datenschutz</a>
|
<a href="#" onclick="openDatenschutz();return false;" style="color:#6b7280;text-decoration:none;">Datenschutz</a>
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
<script>
|
<script>
|
||||||
function toggleTheme() {
|
function toggleTheme() {
|
||||||
const html = document.documentElement;
|
const html = document.documentElement;
|
||||||
@@ -297,6 +298,16 @@
|
|||||||
const savedTheme = localStorage.getItem("theme") || "light";
|
const savedTheme = localStorage.getItem("theme") || "light";
|
||||||
document.documentElement.setAttribute("data-theme", savedTheme);
|
document.documentElement.setAttribute("data-theme", savedTheme);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Besucherzähler laden
|
||||||
|
fetch('/api/counter.php')
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => {
|
||||||
|
document.getElementById('visitor-count').textContent = data.formatted;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
document.getElementById('visitor-count').textContent = '-';
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user