38443-vm/auth/session.php
Flatlogic Bot 4883125cda v2
2026-02-15 10:30:17 +00:00

21 lines
437 B
PHP

<?php
session_start();
require_once __DIR__ . '/../db/config.php';
function getCurrentUser() {
if (!isset($_SESSION['user_id'])) {
return null;
}
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
return $stmt->fetch();
}
function requireLogin() {
if (!isset($_SESSION['user_id'])) {
header('Location: auth/login.php');
exit;
}
}