91 lines
2.1 KiB
PHP
91 lines
2.1 KiB
PHP
<?php
|
|
// Vor allen includes, vor jeglicher Ausgabe
|
|
session_set_cookie_params([
|
|
'lifetime' => 0, // bis Browser geschlossen
|
|
'path' => '/', // Gültig für ganze Domain
|
|
'domain' => '', // aktuelle Domain
|
|
'secure' => false, // true nur für HTTPS
|
|
'httponly' => true,
|
|
'samesite' => 'Lax'
|
|
]);
|
|
session_start();
|
|
|
|
|
|
$error = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = $_POST['username'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
// Beispiel: feste Zugangsdaten
|
|
if ($username === 'admin' && $password === 'secret') {
|
|
$_SESSION['user_logged_in'] = true;
|
|
$_SESSION['username'] = $username;
|
|
|
|
header("Location: index.php");
|
|
exit;
|
|
} else {
|
|
$error = 'Login fehlgeschlagen';
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Login</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<body>
|
|
|
|
<div class="login-container">
|
|
<button id="darkModeToggle">🌙 Dark Mode</button>
|
|
|
|
<div class="login-box">
|
|
|
|
<h2>Login</h2>
|
|
|
|
<?php if ($error): ?>
|
|
<p class="login-error"><?= htmlspecialchars($error) ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="post">
|
|
<input type="text" name="username" placeholder="Benutzername" required>
|
|
<input type="password" name="password" placeholder="Passwort" required>
|
|
<button type="submit">Login</button>
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
|
|
<script>
|
|
const toggle = document.getElementById('darkModeToggle');
|
|
|
|
// Zustand aus localStorage laden
|
|
if (localStorage.getItem('darkMode') === 'enabled') {
|
|
document.body.classList.add('dark-mode');
|
|
}
|
|
|
|
toggle.addEventListener('click', () => {
|
|
document.body.classList.toggle('dark-mode');
|
|
|
|
if (document.body.classList.contains('dark-mode')) {
|
|
localStorage.setItem('darkMode', 'enabled');
|
|
} else {
|
|
localStorage.setItem('darkMode', 'disabled');
|
|
}
|
|
});
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|