初始化版本

This commit is contained in:
LL
2025-11-18 14:30:07 +08:00
commit 78d06a2841
20 changed files with 1346 additions and 0 deletions

30
auth.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
// 简易会话认证
session_start();
require_once __DIR__ . '/config.php';
function is_logged_in(): bool {
return !empty($_SESSION['logged_in']);
}
function require_login(): void {
if (!is_logged_in()) {
$target = 'login.php';
if (!headers_sent()) {
header('Location: ' . $target);
} else {
echo '<script>location.replace("' . $target . '")</script>';
echo '<noscript><meta http-equiv="refresh" content="0;url=' . $target . '"></noscript>';
}
exit;
}
}
function require_api_auth(): void {
if (!is_logged_in()) {
header('Content-Type: application/json; charset=utf-8');
http_response_code(401);
echo json_encode(['error' => 'unauthorized']);
exit;
}
}