View sourcecode

The following files exists in this folder. Click to view.

login.php

28 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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;