📂 File Browser

/applications/includes
🌙 Dark Mode
🎯 Quick Launch:

📁 Directories

📄 Files

🐘 auth.php
▶ Open 📄 View Source
🐘 config.php
▶ Open 📄 View Source
🐘 functions.php
▶ Open 📄 View Source

📄 Source: auth.php

<?php
// Authentication functions
require_once 'db.php';

function isLoggedIn() {
    return isset($_SESSION['user_id']) && isset($_SESSION['login_time']);
}

function getCurrentUser() {
    if (!isLoggedIn()) return null;
    return getUser($_SESSION['user_id']);
}

function loginUser($userId) {
    $_SESSION['user_id'] = $userId;
    $_SESSION['login_time'] = time();
}

function logoutUser() {
    $_SESSION = [];
    session_destroy();
}

function requireLogin() {
    if (!isLoggedIn()) {
        header('Location: login.php?redirect=' . urlencode($_SERVER['REQUEST_URI']));
        exit();
    }
}

function requireForumAccess($forumId) {
    requireLogin();
    $user = getCurrentUser();
    if (!canManageForum($forumId, $user['id'])) {
        header('Location: index.php?error=You do not have permission to access this forum');
        exit();
    }
}

function requireForumOwner($forumId) {
    requireLogin();
    $user = getCurrentUser();
    if (!isForumOwner($forumId, $user['id'])) {
        header('Location: index.php?error=Only the forum owner can perform this action');
        exit();
    }
}

function checkSessionTimeout() {
    if (isset($_SESSION['login_time'])) {
        if (time() - $_SESSION['login_time'] > SESSION_TIMEOUT) {
            logoutUser();
            return false;
        }
        return true;
    }
    return true;
}
?>
← Back