2024-05-31 12:49:47 +02:00

35 lines
717 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";
Headers::html();
$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);
?>
<h1>Visitor count: <?= $cnt ?></h1>
</body>
</html>