<?php
session_start();

$host = 'localhost';
$db   = 'diplomaster';
$user = 'root';
$pass = 'root';
$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];

try {
    $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
    die("Error de conexión: " . $e->getMessage());
}

function is_logged_in() {
    return isset($_SESSION['profesor']);
}

function redirect_if_not_logged_in() {
    if (!is_logged_in()) {
        header('Location: index.php');
        exit;
    }
}