load(); require_once __DIR__ . '/auth_functions.php'; // If already logged in, redirect to dashboard if (isLoggedIn()) { header("Location: /index.php"); exit; } $error = ''; $redirect = $_GET['redirect'] ?? 'index.php'; $reason = $_GET['reason'] ?? ''; // Handle login form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username'] ?? ''); $password = $_POST['password'] ?? ''; if (empty($username) || empty($password)) { $error = 'Vul je gebruikersnaam en wachtwoord in.'; } else { $result = attemptLogin($username, $password); if ($result['success']) { // Redirect to original page or dashboard $redirectUrl = '/' . ltrim(urldecode($redirect), '/'); // Security: only allow relative redirects if (strpos($redirectUrl, '//') !== false || strpos($redirectUrl, 'http') === 0) { $redirectUrl = '/index.php'; } header("Location: $redirectUrl"); exit; } else { $error = $result['error']; } } } ?> Inloggen - Telvero Talpa