The following files exists in this folder. Click to view.
login.php28 lines UTF-8 Unix (LF)
<?php
session_start();
include("db.php");
$user = $_POST['user'];
$pass = $_POST['pass'];
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$user]);
$found = $stmt->fetch(PDO::FETCH_ASSOC);
if ($found && $found['password'] === $pass) {
$_SESSION['user'] = $user;
if (isset($_POST['remember'])) {
setcookie("savedUser", $user, time() + 3600 * 24 * 30);
}
header("location: admin.php");
exit();
} else {
header("location: index.php?mess=Fel användarnamn eller lösenord.");
exit();
}
?>