Refactored file system
Changed the file system to a more ordered state and updated links in files accordingly. Also the reffering to files is now uniform
This commit is contained in:
32
php/login.php
Normal file
32
php/login.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
$usersFile = __DIR__ . "../data/users.json";
|
||||
if (!file_exists($usersFile)) {
|
||||
die("Benutzerdaten fehlen!");
|
||||
}
|
||||
|
||||
$users = json_decode(file_get_contents($usersFile), true);
|
||||
$loginOk = false;
|
||||
|
||||
if (is_array($users)) {
|
||||
foreach ($users as $user) {
|
||||
if ($user['username'] === $username && $user['password'] === $password) {
|
||||
$loginOk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($loginOk) {
|
||||
$_SESSION['loggedIn'] = true;
|
||||
$_SESSION['username'] = $username;
|
||||
header("Location: ./admin.php");
|
||||
exit;
|
||||
} else {
|
||||
header("Location: ../pages/login.html?error=1");
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user