2024-05-24 13:46:06 +02:00

36 lines
718 B
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<?php include_once "../../base/meta.php" ?>
<title>Counter</title>
</head>
<body>
<?php
// PHP
include_once "../../base/settings.php";
include_once "../../base/headers.php";
$fh = fopen("./data/counter.txt", "r+");
if (flock($fh, LOCK_EX)) {
$cnt = intval(fgets($fh));
if (!isset($_COOKIE["counter-visit"])) {
rewind($fh);
$cnt += 1;
fputs($fh, strval($cnt));
setcookie("counter-visit", "true", ["expires" => time() + 60 * 60 * 24, "samesite" => "strict", "secure" => true, "httponly" => true]);
}
}
flock($fh, LOCK_UN);
fclose($fh);
Headers::html();
?>
<h1>Visitor count: <?= $cnt ?></h1>
</body>
</html>