31 lines
699 B
PHP
31 lines
699 B
PHP
<?php
|
|
session_start();
|
|
require 'db.php';
|
|
|
|
$username = $_POST['username'];
|
|
$password = $_POST['password'];
|
|
|
|
$sql = "SELECT * FROM users WHERE username = ?";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$username]);
|
|
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password_hash'])) {
|
|
|
|
$_SESSION['user_id'] = $user['user_id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
$_SESSION['role'] = $user['role'];
|
|
|
|
// Rollenbasierte Weiterleitung
|
|
if ($user['role'] === 'admin') {
|
|
header("Location: admin_dashboard.php");
|
|
} else {
|
|
header("Location: dashboard.php");
|
|
}
|
|
exit();
|
|
|
|
} else {
|
|
echo "Falscher Benutzername oder Passwort!";
|
|
}
|
|
?>
|