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
();
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"$usertime() + 3600 24 30);
    }

    
header("location: admin.php");
    exit();

} else {
    
header("location: index.php?mess=Fel användarnamn eller lösenord.");
    exit();
}
?>