first commit
This commit is contained in:
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
function requireLogin(): void
|
||||
{
|
||||
if (empty($_SESSION["idUtente"])) {
|
||||
$cartellaScript = basename(dirname($_SERVER["SCRIPT_NAME"] ?? ""));
|
||||
$login = $cartellaScript === "PHP" ? "index.php" : "../index.php";
|
||||
header("Location: " . $login . "?errore=accesso");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function requireRole(string $ruolo): void
|
||||
{
|
||||
requireLogin();
|
||||
|
||||
if (($_SESSION["ruolo"] ?? null) !== $ruolo) {
|
||||
header("Location: ../dashboard.php?errore=autorizzazione");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function dashboardForRole(?string $ruolo): string
|
||||
{
|
||||
$destinazioni = [
|
||||
"cliente" => "cliente/dashboard.php",
|
||||
"personale" => "personale/dashboard.php",
|
||||
"proprietario" => "proprietario/dashboard.php",
|
||||
];
|
||||
|
||||
return $destinazioni[$ruolo] ?? "index.php";
|
||||
}
|
||||
|
||||
function e(mixed $valore): string
|
||||
{
|
||||
return htmlspecialchars((string) $valore, ENT_QUOTES, "UTF-8");
|
||||
}
|
||||
|
||||
function postMethod(): bool
|
||||
{
|
||||
return ($_SERVER["REQUEST_METHOD"] ?? "GET") === "POST";
|
||||
}
|
||||
Reference in New Issue
Block a user