The following files exists in this folder. Click to view.
login.php28 lines UTF-8 Unix (LF)
<?php
session_start();
require_once "db.php";
$username = trim($_POST["username"] ?? "");
$password = trim($_POST["password"] ?? "");
if ($username === "" || $password === "") {
header("Location: index.php?mess=Tomma fält är inte tillåtna.");
exit;
}
$sql = "SELECT userId, username FROM user WHERE username=? AND password=? LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$res = $stmt->get_result()->fetch_assoc();
if (isset($res["userId"])) {
$_SESSION["username"] = $res["username"];
header("Location: admin.php?mess=Inloggning lyckades.");
exit;
}
header("Location: index.php?mess=Felaktiga inloggningsuppgifter.");
exit;