Files
sachgiaokhoaorg/app/Libraries/PdfAccess.php
T
sachgiaokhoaorg e6b265db99 Sách Giáo Khoa Việt Nam - sachgiaokhoa.org
CodeIgniter 4 website:
- Catalog 999 SGK (lớp 1-12) từ API, lọc theo lớp/môn/NXB, tìm kiếm
- Trang chủ grouped browse (bậc học -> lớp -> môn, ưu tiên môn quan trọng)
- Chi tiết sách: metadata đầy đủ, cover nghệ thuật /thumb/{W}x{H}/
- Đọc online qua gate captcha + countdown, PDF viewer pdf.js
- Download: captcha + token một lần + auto cache-bust version
- Tự đồng bộ catalog/cover khi API thay đổi (refresh:catalog)
- Legal: DMCA, miễn trừ trách nhiệm, điều khoản, bảo mật, liên hệ
2026-08-23 07:05:49 +00:00

32 lines
789 B
PHP

<?php
declare(strict_types=1);
namespace App\Libraries;
/**
* Session-based PDF view access, granted after captcha.
* One grant (2h) unlocks both the online viewer and the download flow for a book.
*/
class PdfAccess
{
private const KEY = 'pdf_access';
public static function grant(string $bookId, int $ttl = 7200): void
{
$map = session()->get(self::KEY) ?? [];
// keep map bounded
if (count($map) > 50) {
$map = array_filter($map, fn($ts) => $ts > time());
}
$map[$bookId] = time() + $ttl;
session()->set(self::KEY, $map);
}
public static function has(string $bookId): bool
{
$map = session()->get(self::KEY) ?? [];
return isset($map[$bookId]) && $map[$bookId] > time();
}
}