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:
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, ',', '.')
|
||||
]);
|
||||
Reference in New Issue
Block a user