Initial commit: struttura base Diplomacy Web App con header/footer e auth

This commit is contained in:
2025-11-21 16:04:22 +00:00
commit 052b8182aa
17 changed files with 367 additions and 0 deletions

25
init.php Executable file
View File

@@ -0,0 +1,25 @@
<?php
require_once __DIR__ . '/config.php';
session_start();
function getPDO(){
static $pdo = null;
if ($pdo === null) {
$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=utf8mb4";
$pdo = new PDO($dsn, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
}
return $pdo;
}
function is_logged_in(){
return !empty($_SESSION['user_id']);
}
function current_user(){
if (!is_logged_in()) return null;
return ['id'=>$_SESSION['user_id'], 'email'=>$_SESSION['user_email']];
}