View sourcecode

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

login.php

66 lines UTF-8 Windows (CRLF)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
session_start
();

$usersFile "users.txt";
$error "";

if (
$_SERVER["REQUEST_METHOD"] === "POST") {
    
$username $_POST["username"] ?? "";
    
$password $_POST["password"] ?? "";

    if (
file_exists($usersFile)) {
        
$users file($usersFileFILE_IGNORE_NEW_LINES);

        foreach (
$users as $user) {
            list(
$storedUser$storedPass) = explode("|"$user);

            if (
$storedUser === $username && $storedPass === $password) {
                
$_SESSION["user"] = $username;
                
header("Location: bank.php");
                exit;
            }
        }
    }

    
$error "Fel användarnamn eller lösenord";
}
?>


<!DOCTYPE html>
<html lang="sv">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>XTG-banken</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
    <div class="bg-dark text-white py-3 mb-4">
        <div class="container text-center">
            <h1>XTG-banken</h1>
            <p>Välkommen till XTG-banken</p>
        </div>
    </div>
    <h2>Logga in</h2>

<?php if ($error): ?>
<div style="color:red"><?= $error ?></div>
<?php endif; ?>
    <main class="container">
        <form method="post">
                <input name="username" placeholder="Användarnamn">
                <input name="password" type="password" placeholder="Lösenord">
                <button type="submit">Logga in</button>
        </form>

        <a href="register.php">Skapa konto</a>

                    </div>
                </div>
            </div>
        </div>
    </main>
</body>
</html>